美文网首页iOS
iOS ,SearchController

iOS ,SearchController

作者: 若风_412d | 来源:发表于2019-04-29 09:15 被阅读0次

1.searchController没有界面控件可供拖拽

只能手写代码

#pragma mark ----搜索

-(void)search{
    //创建UISearchController
    _searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
    //设置代理
    _searchController.delegate = self;
    _searchController.searchResultsUpdater= self;
    
    self.searchController.dimsBackgroundDuringPresentation=NO;//背景变暗色
    self.searchController.obscuresBackgroundDuringPresentation=NO;//背景模糊

    //自定义中文取消
    _searchController.searchBar.showsCancelButton = YES;
    UIButton *canceLBtn = [_searchController.searchBar valueForKey:@"cancelButton"];
    [canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
    [canceLBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    
    _searchController.searchBar.placeholder = @"输入";
    //背景
  //  _searchController.searchBar.barTintColor = kWhiteColor ;
    
    //边框
  // _searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;


    // 添加 searchbar 到 headerview
    self.tableView.tableHeaderView = _searchController.searchBar;
}

https://www.cnblogs.com/jukaiit/p/5063942.html

2城市选择器

https://www.jianshu.com/p/e1d7a1030cb6

这个东西缺城市 ,看上面的链接,可以手动添加,城市id不重复就行了。


屏幕快照 2019-05-29 下午3.18.14.png // BEB72782875A38E8161CCCAFF6B8C801.png
//1.把searchController加到view上;

@property (nonatomic, strong) UISearchController *searchController;


         UIView * headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,300, 88)];

           [headView addSubview: self.searchController.searchBar];

3.searchBar导航条高度变化

push进一个search的页面再出来有缝隙


截屏2019-10-25下午5.58.10.png 截屏2019-10-25下午5.59.01.png
//原因
    self.navigationItem.titleView = self.searchController.searchBar;
//只需要加上下面的代码就ok了

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.searchController.active = NO;
    self.navigationItem.titleView = nil;
    
}

相关文章

网友评论

    本文标题:iOS ,SearchController

    本文链接:https://www.haomeiwen.com/subject/tjeenqtx.html