适配iOS7之—UITableView和UISearchBar(待续)

来源:互联网 发布:淘宝商业的竞争环境 编辑:程序博客网 时间:2024/05/02 00:07
 

iOS7中,如果用UITableViewStyleGrouped的话,里面的  cell会比原来的拉长了 ,这样做应该是为了统一和UITableViewStylePlain风格时cell的大小一致,所以改用UITableViewStylePlain后,就没问题了,而且在iOS7中,使用UITableViewStyleGrouped风格时,上面会出现  headView ,大概占了35个像素,使用  UITableViewStyleGrouped 风格的朋友们注意了,如下图为使用UITableViewStyleGrouped时的差异: 屏幕快照 2013-09-27 下午10.27.49

图1-1

还有就是iOS7下的UITableView增加了一个  UITableViewWrapperView 子视图,UITableViewCell变成了UITableViewWrapperView的子视图,而在iOS6中,UITableViewCell是UITableView的子视图。 

用代码表现出来就是:

1
2
3

UITableView *tableView = (UITableView *)cell.superview.superview; //in iOS7

 

UITableView *tableView = (UITableView *)cell.superview; //in iOS6

如果之前定制cell的时候,用下面代码取tableView的需要做适配了。

1

UITableView *tableView = (UITableView *) self  .superview;

还有就是现在可以直接设置  UITableView的背景颜色 了: 

1

_loginTable.backgroundColor = [UIColor redColor];

另一个问题就是我使用  UISearchBar 的时候,Apple在iOS7中也做了调整。如下图: 

屏幕快照 2013-09-27 下午11.22.03

图1-2

相信很多人在使用UISearchBar的时候,都比较喜欢上面的那种去了背景色的样子,在iOS6中我是使用下面这种方式去除背景色:

1
2
3
4
5
6
7
8
9
10
11
12
//for iOS6

for  (UIView *subview in   self  .search.subviews) {

 

      if  ([subview isKindOfClass: NSClassFromString  (  @"UISearchBarBackground"  )]) {

 

          [subview removeFromSuperview];

 

          break  ;

 

      }

 
}

而今天突然发现,纳尼,在iOS7中,搜索框消失了,用小伙伴的方法看了一下,原来视图树改变了。如下图:

uisearchbar

在iOS7中,UISearchBar的子视图变成一个UIView,所以原来的方法不管用了,但是看了一下文档,在iOS7中新增了一个barTintColor的属性,我们可以设置  barTintColor 为clearColor,便得到图1-2中的效果。 

1
2
3
4
5
6
7
//for iOS 7
 

if  ([  self  .search respondsToSelector:  @selector (barTintColor)]) {

 

[  self  .search setBarTintColor:[UIColor clearColor]];

 
}

0 0
原创粉丝点击