iOS8以后 UISearchController的用法
查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面):
1. 声明属性 @property (nonatomic, strong) UISearchController *searchController;
2. 调用方法: [self searchController];
3. 实现: - (UISearchController *)searchController {
if (!_searchController) {
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
// searchBar
_searchController.searchBar.frame = CGRectMake(0, 0, kWidth - 40, 36);
_searchController.searchBar.placeholder = @"搜索";
_searchController.searchBar.barTintColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
// searchBarTextField
UITextField *searchField = nil;
searchField = [[_searchController.searchBar.subviews objectAtIndex:0].subviews lastObject];
searchField.backgroundColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
UIColor *color = [UIColor whiteColor];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"您也可以输入关键字搜索" attributes:@{NSForegroundColorAttributeName:color}];
_searchController.view = [[UIView alloc] initWithFrame:CGRectMake(20, 352/2, kWidth - 40, 36)];
[_searchController.view addSubview:_searchController.searchBar];
_searchController.view.backgroundColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
[self.tableHeaderView addSubview:self.searchController.view];
}
return _searchController;
}
4. 查看效果:
iOS8以后 UISearchController的用法的更多相关文章
- UISearchController 的用法[点击搜索框,自动到顶部]
//在ViewDidLoad里面如下代码 self.searchViewController = [[UISearchController alloc]initWithSearchResultsCon ...
- 【原】iOS优秀开源项目总结
网上此类帖子博客不少,不过自己没整理过的东西始终是别人,现开此贴加以总结,持续更新!站在巨人的肩膀上才能站得高看得远. 第一部分:UI类 1.毛玻璃模糊效果 RNFrostedSidebar 一个iO ...
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
1.searchResultsUpdater:设置显示搜索结果的控制器 ? 1 _mySearchController.searchResultsUpdater = self; 2.dimsB ...
- UISearchController的使用。(iOS8+)
这种方法早就发现了,不过一致没用,今天拿过来用,发现了一些问题. 1.这个东西和表视图结合使用很方便,首先,创建新的工程,将表视图控制器作为工程的根视图,并且添加一个导航(当然,你可以不这样做,但是你 ...
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- CoreLocation在iOS8上用法的变化
1.在使用CoreLocation前需要调用如下函数[iOS8专用]: iOS8对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法: (1)始终允许访 ...
- Swift - 使用UISearchController实现带搜索栏的表格
我原来写过一篇文章“Swift - 带结果列表的搜索条(UISearchDisplayController)的用法”,当时是使用UISearchDisplayController来实现带有搜索功能的列 ...
- Swift - 带结果列表的搜索条(UISearchDisplayController)的用法
(注:自iOS8起,苹果便废弃UISearchDisplayController的使用,改为使用UISearchController来实现类似功能,可参考我的另一篇文章“Swift - 使用UISea ...
随机推荐
- Android通过编码实现GPS开关
在Android 2.2以后才可使用 import android.content.ContentResolver; import android.content.Context; import an ...
- 【原创】C#搭建足球赛事资料库与预测平台(2) 数据库与XCode组件
本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新 开源C#彩票数据资料库系列文章总目录:[目录]C#搭建足球赛事资料库与预测平台与彩票数据分析目录 本篇文章开始将逐步 ...
- 清除WebLogic8.1缓存
在Domain目录下面有一个以server命名的文件夹,删除整个文件夹就可以了.
- Android 学习笔记 Service服务与远程通信...(AIDL)
PS:这一章节看的我有几分迷茫,不是很容易理解...不过还好总算是明白了一大半了...基本的迷惑是解决了... 学习内容: 1.跨应用启动服务... 2.跨应用绑定服务... 3.跨应用实现通信... ...
- IOS开发UI基础文本属性Attributes
文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFo ...
- 【Android进阶系列教程】前言
起因 因为初学Android的时候还没有写博客的意识,现在Android的门是入了,正在进阶的道路上行走,但是就这一路也走了不少的弯路.我想,总得来说Android入门还是比较容易的,网络资源比较丰富 ...
- [Architect] Abp 框架原理解析(4) Validation
本节目录 介绍 DataAnnotations ICustomValidate IShouldNormalize 实现Abp Validation 介绍 Abp中在Application层集成了val ...
- LNK1179 无效或损坏的文件: 重复的 COMDAT“_IID_IDispatchEx”
fatal error LNK1179: invalid or corrupt file: duplicate comdat "XXX" LNK1179 无效或损坏的文件: 重复 ...
- C# 泛型简介
摘要:本文讨论泛型处理的问题空间.它们的实现方式.该编程模型的好处,以及独特的创新(例如,约束.一般方法和委托以及一般继承).此外,本文还讨论 .NET Framework 如何利用泛型. 下载 Ge ...
- FreeBSD 10 发布
发行注记:http://www.freebsd.org/releases/10.0R/relnotes.html 下文翻译中... 主要有安全问题修复.新的驱动与硬件支持.新的命名/选项.主要bug修 ...