tableview和searchbar的適配

iOS7中,若是用UITableViewStyleGrouped的話,裏面的 cell會比原來的拉長了,這樣作應該是爲了統一和UITableViewStylePlain風格時cell的大小一致,因此改用UITableViewStylePlain後,就沒問題了,並且在iOS7中,使用UITableViewStyleGrouped風格時,上面會出現 headView ,大概佔了35個像素,使用 UITableViewStyleGrouped 風格的朋友們注意了,以下圖爲使用UITableViewStyleGrouped時的差別:屏幕快照 2013-09-27 下午10.27.49app

圖1-1ui

還有就是iOS7下的UITableView增長了一個 UITableViewWrapperView 子視圖,UITableViewCell變成了UITableViewWrapperView的子視圖,而在iOS6中,UITableViewCell是UITableView的子視圖。spa

用代碼表現出來就是:3d

1
2
3

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

 

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

若是以前定製cell的時候,用下面代碼取tableView的須要作適配了。ci

1

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

還有就是如今能夠直接設置 UITableView的背景顏色 了:文檔

1

_loginTable.backgroundColor = [UIColor redColor];get

另外一個問題就是我使用 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]];

 
}

至此,目前我在適配iOS7的時候,就遇到這兩個問題,寫出來,分享給你們。

今天看到一個笑話,快笑得不能自已了:

爲何練葵花寶典必定要先自宮?

網友答覆:練成神功後,絕對會屌爆了,因此要先防患於未然。O(∩_∩)O~

相關文章
相關標籤/搜索