IOS学习笔记——UISearchBar和UISearchDisplayController
来源:互联网 发布:淘宝怎么看店铺等级 编辑:程序博客网 时间:2024/06/10 06:00
随便记录一下开发中遇到的一些问题
- 关于代理
c
// searchResultsDataSource 就是 UITableViewDataSource searchDisplayController.searchResultsDataSource = self; // searchResultsDelegate 就是 UITableViewDelegate searchDisplayController.searchResultsDelegate = self;
别忘了这个:
c
searchDisplayController.delegate = self;
- 如果想设置 cancelbutton的颜色:
c
searchBar.tintColor = [UIColor whiteColor];
- 如果想设置 cancelbutton的字体:
在IOS7下这样设置:
c
-(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下这样设置:
c
- (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的背景颜色可以这样设置:
c
searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_bg"]];
- 设置UISearchDisplayController是否激活:
eg:当我点击 搜索列表 的时候,我想让 searchbar恢复原状,即导航栏也恢复原状时;
c
[searchDisplayController setActive:NO animated:YES];
tips:改变cancelbutton的颜色
在didFinishLaunchingWithOptions中
把cancelbutton的颜色变成白色的代码如下:
c
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal];
相关链接:How to change cancel button tint color of UISearchBar in iOS7
0 0
- IOS学习笔记——UISearchBar和UISearchDisplayController
- iOS UISearchBar和UISearchDisplayController
- iOS UISearchBar 和 UISearchDisplayController的使用
- IOS UISearchBar + UISearchDisplayController使用
- iOS UISearchDisplayController学习笔记
- 【IOS 开发学习总结-OC-53】★★ios开发UI 控件——UISearchBar与UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchBar和UISearchDisplayController
- UISearchDisplayController 和 UISearchBar
- UISearchBar和UISearchDisplayController
- 数据结构 课程设计哈夫曼编码
- iOS 表单首字母大写
- sed命令详解 转载:http://blog.chinaunix.net/u/22677/showart_1076318.html
- iOS8 SDK中部份更新
- IOS学习笔记-UITableView表索引的颜色设置
- IOS学习笔记——UISearchBar和UISearchDisplayController
- zookeeper原理与使用
- MJPEG+PCM合成AVI视频格式文件
- Oracle Optimizer CBO RBO
- Java Comparable vs Comparator
- Java ExecutorService线程池中的小坑——关于线程池中抛出的异常处理
- JavaScript、jQuery、HTML5、Node.js实例大全-读书笔记1
- R -ggplot2 气泡图
- 扫描给定的包及其子包下面的所有类