美文网首页
iOS 导航栏上加搜索框

iOS 导航栏上加搜索框

作者: 匠金科技 | 来源:发表于2017-02-19 15:03 被阅读0次

UISearchBar * searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 255.0f, 44.0f)];    searchbar.delegate = self;

[searchbar setTintColor:[UIColor redColor]];

[searchbar setPlaceholder:@"搜索游记、旅行地与用户"];

UIBarButtonItem * searchButton = [[UIBarButtonItem alloc]initWithCustomView:searchbar];    

 self.navigationItem.rightBarButtonItem = searchButton;

最后在- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 方法里面写搜索方法就可以了。比较简单,做个记录。

相关文章

网友评论

      本文标题: iOS 导航栏上加搜索框

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