iOS 导航栏上加搜索框

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 导航栏上加搜索框)