UISearchController
UISearchBar http://blog.sina.com.cn/s/blog_7b9d64af0101dfg8.html
UISearchController
//创建
self.searchC = [[UISearchController alloc] initWithSearchResultsController:nil];
//设置代理
self.searchC.searchResultsUpdater = self;
self.searchC.delegate = self;
self.searchC.searchBar.delegate = self; //然后searchbar的代理方法就可以用了
self.searchController.searchBar.placeholder = NSLocalizedString(@"UISearchController", @"please add string file");
//设置UISearchController的显示属性,以下3个属性默认为YES //搜索时,背景变暗色 _searchController.dimsBackgroundDuringPresentation = NO; //搜索时,背景变模糊 _searchController.obscuresBackgroundDuringPresentation = NO; //隐藏导航栏 _searchController.hidesNavigationBarDuringPresentation = NO;
//设置searchbar自适应位置
[self.searchC.searchBar sizeToFit];
//设置背景颜色
self.searchC.searchBar.barTintColor = [UIColor yellowColor];
//搜索栏的内容发生变化时, 会触发代理方法
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController;