UISearchBar基本设置 和 代理方法
来源:互联网 发布:人工智能 教育 编辑:程序博客网 时间:2024/05/16 05:00
UISearchBar 基本设置
UISearchBar 在延展中签订代理协议
@interface RootViewController () <UISearchBarDelegate>@end
UISearchBar 创建对象
UISearchBar *search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 100, 375, 80)]; [self.view addSubview:search]; [search release];
UISearchBar 基本属性
search.placeholder = @"search"; /* 占位字符 */search.prompt = @"蓝鸥"; /* 搜索框提示标题 */search.text = @"lanou"; /* 开始时的字符 */search.barStyle = 1;search.barTintColor = [UIColor purpleColor];/* 设置搜索框颜色 */search.translucent = YES; /* 透明设置 */
UISearchBar 输入设置
search.autocapitalizationType = 4; /* 枚举 1无设置 2单词首字母大写 3一句话首字母大写 4所有字母都大写 */search.keyboardType = 1; /* 键盘类型 */ /* searchButton设置 */search.showsBookmarkButton = YES; /* 书签button */search.showsCancelButton = YES; /* 取消button 当输入框为第一响应者时 取消button 可以点击 */search.showsSearchResultsButton = YES; /* 搜索结果button */[search setShowsCancelButton:YES animated:YES]; /* 动画效果的取消button */
UISearchBar 下面的Button设置
search.showsScopeBar = YES; /* 范围button显示 */search.scopeButtonTitles = @[@"0", @"1", @"2"];/* 元素个数为范围条内button个数 */search.selectedScopeButtonIndex = 2; /* 初始范围button选择 *//* 背景图设置 */[search setBackgroundImage:[UIImage imageNamed:@"01.jpg"]]; /* 搜索框设置背景照片 */[search setScopeBarBackgroundImage:[UIImage imageNamed:@"01.jpg"]]; /* 给范围button 设置背景照片*/[search setImage:[UIImage imageNamed:@"01.jpg"] forSearchBarIcon:UISearchBarIconResultsList state:(UIControlStateNormal)];/* 给搜索结果列表按钮设置图片 */
UISearchBar 代理方法 关于文本的监控
控制搜索框是否可以开始编辑
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { return YES;}
搜索框开始编辑时调用
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { /* 点击button时以动画效果出现cancelButton */ [searchBar setShowsCancelButton:YES animated:YES];}
控制搜索框是否可以结束编辑回收键盘
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { return NO;}
输入框开始输入方法开始执行 输入框输入的内容即searchText
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ NSLog(@"%@", searchText);}
搜索框button点击代理方法
/* 点击搜索按钮(输入键盘上得search)时调用 */- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { /* 打印当前运行方法 */ NSLog(@"%s", __func__);}/* 点击书签button时调用(书签button在和搜索结果列表button一个位置) */- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar{ NSLog(@"%s", __func__);}/* 点击取消button时调用 */- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { /* 搜索框以动画效果消失 */ [searchBar setShowsCancelButton:NO animated:YES]; /* 收回键盘 */ [searchBar resignFirstResponder]; NSLog(@"%s", __func__);}/* 点击搜索结果button时调用 */- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar { NSLog(@"%s", __func__);}/* 选择范围button时调用 并提供选择button的下标 */- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope { NSLog(@"%s ,%ld", __func__, selectedScope);}
0 0
- UISearchBar基本设置 和 代理方法
- UISearchbar 常用代理方法
- UISearchbar 常用代理方法
- UISearchbar 常用代理方法
- UISearchBar基本用法及searchBar常用代理方法
- UISearchBar基本用法及searchBar常用代理方法
- UITextView的基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- UIScrollView基本用法和代理方法
- iOS UICollectionView基本属性 和 代理方法
- UIScrollView基本用法和代理方法
- CURL常用命令
- leetcode:TwoSum
- Java构造和解析Json数据的两种方法详解(02)
- iterator_traits 存在的作用与意义
- Python 爬虫 urllib2异常处理
- UISearchBar基本设置 和 代理方法
- 我决定开始写技术博客了
- 扑克排序,按花色、值排序(2015年9月10日)
- REHL5.4工作站上搭建VNCSERVER
- Android简单音乐播放器
- postgresql在ubuntu下安装
- httpclient
- MinGW 介绍
- Ubuntu中安装及配置postgreSQL