IOS--常用控件--UISearchBar和UISearchDisplayController
2015-03-04 15:53
417 查看
一、UISearchBar单独使用时,设置样式:
UIView *view =[mySearchBar.subviews objectAtIndex:0];
// view.backgroundColor =[UIColor clearColor];
for (UIView *backview in view.subviews) {
if ([backview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[backview removeFromSuperview];
break;
}
}
二、UISearchBar和UISearchDisplayController结合使用时:
关于代理
别忘了这个:
如果想设置 cancelbutton的颜色:
如果想设置 cancelbutton的字体: 在IOS7下这样设置:
在IOS5/6下这样设置:
如果想设置 UISearchBar的背景颜色可以这样设置:
设置UISearchDisplayController是否激活: eg:当我点击 搜索列表 的时候,我想让 searchbar恢复原状,即导航栏也恢复原状时;
UIView *view =[mySearchBar.subviews objectAtIndex:0];
// view.backgroundColor =[UIColor clearColor];
for (UIView *backview in view.subviews) {
if ([backview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[backview removeFromSuperview];
break;
}
}
二、UISearchBar和UISearchDisplayController结合使用时:
关于代理
// searchResultsDataSource 就是 UITableViewDataSource searchDisplayController.searchResultsDataSource = self; // searchResultsDelegate 就是 UITableViewDelegate searchDisplayController.searchResultsDelegate = self;
别忘了这个:
searchDisplayController.delegate = self;
如果想设置 cancelbutton的颜色:
searchBar.tintColor = [UIColor whiteColor];
如果想设置 cancelbutton的字体: 在IOS7下这样设置:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{ self.searchDisplayController.searchBar.showsCancelButton = YES; UIButton *cancelButton; UIView *topView = self.searchDisplayController.searchBar.subviews[0]; for (UIView *subView in topView.subviews) { if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton"))]) { cancelButton = (UIButton*)subView; } } if (cancelButton) { //Set the new title of the cancel button [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal]; } }
在IOS5/6下这样设置:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{ self.searchDisplayController.searchBar.showsCancelButton = YES; UIButton *cancelButton = nil; for (UIView *subView in self.searchDisplayController.searchBar.subviews) { if ([subView isKindOfClass:UIButton)]) { cancelButton = (UIButton*)subView; } } if (cancelButton){ //Set the new title of the cancel button [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal]; } }
如果想设置 UISearchBar的背景颜色可以这样设置:
searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_bg"]];
设置UISearchDisplayController是否激活: eg:当我点击 搜索列表 的时候,我想让 searchbar恢复原状,即导航栏也恢复原状时;
[searchDisplayController setActive:NO animated:YES];
相关文章推荐
- iOS - 搜索框UISearchController的使用(iOS8.0之后替代UISearchBar + UISearchDisplayController的组合)
- 【IOS 开发学习总结-OC-53】★★ios开发UI 控件——UISearchBar与UISearchDisplayController
- iOS--UISearchBar和UISearchDisplayController
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController的组合)
- 【学习ios之路:UI系列】(UISearchBar,UISearchDisplayController) 和UISearchController(iOS8新特性)
- iOS:搜索栏控件UISearchBar and SearchDisplayController的使用
- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
- UI_搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
- iOS开发-UI控件:关于使用UISearchDisplayController
- iOS UISearchBar和UISearchDisplayController
- uisearchbar点击时下边有阴影原来是苹果自带的控件UISearchDisplayController
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
- iOS UISearchBar 和 UISearchDisplayController的使用
- IOS UISearchBar + UISearchDisplayController使用
- IOS-模糊搜索UISearchBar+UISearchDisplayController
- IOS学习笔记——UISearchBar和UISearchDisplayController
- UISearchBar 和 UISearchDisplayController 没有在UITableView 的headerView 导致searchResultsTableView的frame出问题
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
- UISearchBar和 UISearchDisplayController的使用
- How do I cover the “no results” text in UISearchDisplayController's searchResultTableView?