搜索框UISearchBar

1\初始化

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 20, 200, 30)];

[self.view addSubview:searchBar];

searchBar.delegate = self;

2\实现代理方法

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {

NSLog(@"开始编辑");

[self presentViewController:[[redViewController alloc] init] animated:YES completion:nil];

return YES;

}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

NSLog(@"改变了");

}

时间: 2024-08-28 23:07:31

搜索框UISearchBar的相关文章

IOS中搜索框UISearchBar及搜索方法的使用

搜索框可以用UISearchBar,并且可以设置代理UISearchBarDelegate. 1 -(void)addSearchBar{ 2 CGRect searchBarRect = CGRectMake(0, 0, self.view.frame.size.width, 44); 3 UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:searchBarRect]; 4 searchBar.placeholder = @"

iOS搜索框UISearchBar

当你在seachBar中输入字母之前的时候,只是用鼠标选中searchBar的时候,如图 终端输出截图如下:(这个时候调用先shouldBeginEditing,之后调用didBeginEditing,) 当你希望选中UISearchBar的时候,键盘自动调用加载到界面,你需要将下面函数的返回值设置为YES: - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { NSLog(@"shouldBeginEditing"

UISearchBar(搜索框)

初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar     UISearchBar * bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)];     [self.view addSubview:bar]; @property(nonatomic)        UIBarStyle              barStyle; 这个属性可以设置searchBar

iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController的组合)

在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISearchDisplayController的组合方式. 添加UISearchController属性: @property(strong, nonatomic) UISearchController *searchController; @property(strong, nonatomic) NS

iOS中UISearchBar(搜索框)使用总结

iOS中UISearchBar(搜索框)使用总结 初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar     UISearchBar * bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)];     [self.view addSubview:bar]; @property(nonatomic)        UIBarStyle              ba

ios UISearchBar搜索框的基本使用

摘要: 小巧简洁的原生搜索框,漂亮而易用,如果我们的应用没有特殊需求,都可以使用它. iOS中UISearchBar(搜索框)使用总结 初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar     UISearchBar * bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)];     [self.view addSubview:bar]; @property(n

iOS开发--UIKit控件之UISearchBar(搜索框)

初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar 1 UISearchBar *bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)]; 2 [self.view addSubview:bar]; 1 // 这个属性可以设置searchBar的搜索 2 @property(nonatomic) UIBarStyle barStyle; 3 // 枚举如下: 4 t

iOS 搜索框之UISearchBar

一.初始化:UISearchBar继承于UIView,我们可以像创建View那样创建searchBar UISearchBar * bar = [[UISearchBar alloc]initWithFrame:CGRectMake(20, 100, 250, 40)]; [self.view addSubview:bar]; 二.属性 @property(nonatomic)        UIBarStyle              barStyle; 这个属性可以设置searchBar的

iOS - Swift UISearchController仿微信搜索框

0x01.创建一个UISearchController 如果传入的searchController为nil,则表示搜索的结果在当前控制器中显示,现在我让它在searchVC中显示. // 创建searchResultVC let searchVC = UIViewController() // 设置背景颜色为红色 searchVC.view.backgroundColor = UIColor.red let searchController = UISearchController(search