UISearchController
因為要做一個帶有搜尋欄的頁面,所以找個下search的方法
iOS7以前是UISearchDisplayController
iOS8以後UISearchDisplayController被UISearchController替代,但是考慮對iOS7的適配,還是採用以前的方法。
基本方法:
1.建立searchbar
UISearchBar* searchBar = [[UISearchBaralloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
searchBar.delegate=self;
2.設定tableview的headerview為searchbar
_tableView.tableHeaderView= searchBar;
2.把searchbar給uisearchdisplaycontroller
dc= [[UISearchDisplayControlleralloc]initWithSearchBar:searchBarcontentsController:self];
dc.searchResultsDataSource=self;
dc.searchResultsDelegate=self;
4.更改搜尋背景和搜尋文字背景
for(UIView*subviewinsearchBar.subviews) {
for(UIView* grandSonViewinsubview.subviews){
if([grandSonViewisKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
grandSonView.alpha=0.0f;
}elseif([grandSonViewisKindOfClass:NSClassFromString(@"UISearchBarTextField")] ){
NSLog(@"Keep textfiedld bkg color");
searchBar.barTintColor= [UIColorblueColor];
grandSonView.backgroundColor= [UIColorredColor];
}else{
//grandSonView.alpha = 0.0f;
grandSonView.backgroundColor= [UIColorredColor];
}
}//for cacheViews
}//subviews
[searchBarsetSearchFieldBackgroundImage:[UIImageimageNamed:@"向量智慧物件"]forState:UIControlStateNormal];
UISearchController的方法:
相關文章
- IOS UISearchBar UISearchController使用iOSUIController
- 蘋果文件 UISearchController的介紹蘋果UIController
- [譯]UISearchController 教程:開始使用UIController
- UISearchController向上偏移64處理UIController
- iOS UISearchController樣式全面設定iOSUIController
- 【轉】如何基於UISearchController深度自定義搜尋UIUIController
- 搜尋框UISearchController的使用及所遇到的坑UIController