标签:
谓词
self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.frame), 40)];
[self addSubview:_searchBar];
// 占位符
[self.searchBar setPlaceholder:@"请输入"];
// 换颜色
[self.searchBar setBarStyle:UIBarStyleBlackOpaque];
// 显示右侧
[self.searchBar setShowsBookmarkButton:YES];
// 显示右侧取消按钮
[self.searchBar setShowsCancelButton:YES animated:YES];
// 显示搜索结果
[self.searchBar setShowsSearchResultsButton:YES];
代理:
1.引入代理
@interface RootViewController ()<UISearchBarDelegate>
2.设置代理
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.rv.searchBar.delegate = self;
}
3.调用方法
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
NSLog(@"cancel");
}
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar{
NSLog(@"搜索已按下");
NSLog(@"%@",searchBar.text);
}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
NSLog(@"start");
return YES;
}
进击的UI----------------UISearchBar(搜索框)
标签:
原文地址:http://www.cnblogs.com/sharkHZ/p/4984191.html