UISearchBar

来源:互联网 发布:java内存泄露定位 编辑:程序博客网 时间:2024/06/08 02:39
UISearchBar

创建
UISearchBar *searchbar = [UISearchBar alloc]initWihtFream:CGRectMake:(x,y,w,h);

设置控件风格
searchbar.barStyle = UIBarStyleBlack;

设置搜素框的初始文字
searchbar.text = @"";

搜索框背景文字
searchBar.prompt = @""

搜索框内提示文字
search.placeholder = @""

向搜索框添加一个图书按钮
search.showBoookmarkButton = YES;

向搜索框添加一个取消按钮
search.showCancelButton = YES;

展示搜索结果按钮
search.showSearchResultsButton = YES;

设置搜索框光标的颜色
searchBar.tintColor = [UIColor redColor];

设置搜索框边框的颜色
searchBar.barTintColor = [UIColor blueColor];

设置搜索框整体风格
search.searchBarStyle = UISearchBarStyleProminent;

设置搜索框的附加切换试图
searchbar.showsScopeBar = YES;
searchbar.scopeButtonTitles = @[@"buttonOne",@"buttonTwo",@"buttonThree"];
searchbar.selectedScopeButtonIndex = 1;

设置键盘的附加试图
UIview *view = [UIview alloc]initWithFream:CGRectMake:(x,y,375,40)];
view.backgroundColor = [UIColor grayColor];
UILabel *label = [UILabel alloc]initWithFream:CGRectMake:(x,y.w.h)];
label.text =@"用于添加扩展功能";
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
[view addSubview:label];
searchBar.inputAccessoryView = view;

添加到视图上
[self.view addSubview:searchbar]
原创粉丝点击