searchbar的使用介绍
searchBar的使用介绍
首先如何创建一个SearchBar实例:
self.searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake(0.0, 20, self.view.bounds.size.width, 40)];
self.searchBar.placeholder=@"搜索";
self.searchBar.showsCancelButton = YES;//显示右边的取消按钮。
self.searchBar.keyboardType = UIKeyboardTypeDefault;//键盘类型
self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;//自动修正
self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;//首字母大写
我们还需要设置代理,然后实现这个里面的方法:
//遵循协议:UISearchBarDelegate
下面是这个协议的方法:
@protocol UISearchBarDelegate <UIBarPositioningDelegate>
@optional
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar; // return NO to not become first responder
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; // called when text starts editing
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar; // return NO to not resign first responder
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar; // called when text ends editing
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText; // called when text changes (including clear)
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text NS_AVAILABLE_IOS(3_0); // called before text changes
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar; // called when keyboard search button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar; // called when bookmark button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar; // called when cancel button pressed
- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar NS_AVAILABLE_IOS(3_2); // called when search results button pressed
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope NS_AVAILABLE_IOS(3_0);
@end
如何消除searchBar中的背景:
// 如何将背景消除:首先我们在调试窗口,打出self.searchBar的层次结构。然后根据这个结构将UISearchBar中的背景视图给remove。我们这样就实现删除背景颜色的效果
[[[[self.searchBar.subviews objectAtIndex:0] subviews] objectAtIndex:0] removeFromSuperview];
如何打出层次结构:
在命令行中,使用recursiveDescription打印出UIView的层次结构,
例如:
po [self.searchBar recursiveDescription]
//打印出得结果为:
<UISearchBar: 0x7ba7f6d0; frame = (0 20; 320 40); text = ''; gestureRecognizers = <NSArray: 0x7ba8cf20>; layer = <CALayer: 0x7ba881f0>>
| <UIView: 0x7ba8b530; frame = (0 0; 320 40); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x7ba8b5a0>>
| | <UISearchBarBackground: 0x7ba8d480; frame = (0 0; 320 40); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7ba8d670>>
| | <UISearchBarTextField: 0x7b7745a0; frame = (0 0; 0 0); text = ''; clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7b7737e0>>
| | | <_UISearchBarSearchFieldBackgroundView: 0x7b778390; frame = (0 0; 0 0); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x7b777df0>>
searchbar的使用介绍的更多相关文章
- 软件介绍:搜索工具 Listary
如今的互联网时代,搜索的重要性我想大家都是认可的.网上的知识浩如烟海,而搜索引擎是通向这些知识的入口.谷歌.百度等搜索引擎给我们带来了极大的便利,也无怪他们成长为如今的互联网巨头. 然而储存在个人硬件 ...
- React 介绍
ttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind The sm ...
- SQLite简单介绍
一.离线缓存 在项目开发中,通常都需要对数据进行离线缓存的处理,如新闻数据的离线缓存等. 说明:离线缓存一般都是把数据保存到项目的沙盒中.有以下几种方式 (1)归档:NSCodeing.NSKeyed ...
- CSS3 background-image背景图片相关介绍
这里将会介绍如何通过background-image设置背景图片,以及背景图片的平铺.拉伸.偏移.设置大小等操作. 1. 背景图片样式分类 CSS中设置元素背景图片及其背景图片样式的属性主要以下几个: ...
- MySQL高级知识- MySQL的架构介绍
[TOC] 1.MySQL 简介 概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL是一种关联数据库管理系统,将数据保存在不同的表中,而 ...
- Windows Server 2012 NIC Teaming介绍及注意事项
Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...
- Linux下服务器端开发流程及相关工具介绍(C++)
去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...
- JavaScript var关键字、变量的状态、异常处理、命名规范等介绍
本篇主要介绍var关键字.变量的undefined和null状态.异常处理.命名规范. 目录 1. var 关键字:介绍var关键字的使用. 2. 变量的状态:介绍变量的未定义.已定义未赋值.已定义已 ...
- HTML DOM 介绍
本篇主要介绍DOM内容.DOM 节点.节点属性以及获取HTML元素的方法. 目录 1. 介绍 DOM:介绍DOM,以及对DOM分类和功能的说明. 2. DOM 节点:介绍DOM节点分类和节点层次. 3 ...
随机推荐
- windows 下 pgsql 拓展开启
环境:windowxp + apache2.2+php5.2.13+postgresql8.3 操作步骤:1.修改php.ini,去掉“extension=php_pgsql.dll ”和“exten ...
- if exists和if not exists关键字用法
在sql语名中,if not exists 即如果不存在,if exists 即如果存在. 下面学习下二者的用法. a,判断数据库不存在时 代码示例: if not exists(select * f ...
- ExtJS 4 树
Tree Panel是ExtJS中最多能的组件之一,它非常适合用于展示分层的数据.Tree Panel和Grid Panel继承自相同的基类,所以所有从Grid Panel能获得到的特性.扩展.插件等 ...
- 转:[译]Autoprefixer:一个以最好的方式处理浏览器前缀的后处理程序
原文来自于:http://www.cnblogs.com/aNd1coder/archive/2013/08/12/3252690.html Autoprefixer解析CSS文件并且添加浏览器前缀到 ...
- Preparing for the Contest
Codeforces Round #222 (Div. 1)B:http://codeforces.com/contest/377/problem/B 题意:m个任务,每个任务会有一个复杂度,然后给 ...
- Linux&shell 之Linux文件权限
写在前面:案例.常用.归类.解释说明.(By Jim) Linux文件权限用户useradd test (添加用户test)userdel test (删除用户test)passwd test(修改用 ...
- [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II
Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...
- Eight(bfs+全排列的哈希函数)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22207 Accepted: 9846 Special Judge ...
- 在外国网站上看到一个用artoolKit做的demo,学习了用gcd创建单列
外国网站:http://www.raywenderlich.com/42266/augmented-reality-ios-tutorial-location-based 看了下里面的demo,源代码 ...
- 【转】EditText大小(长宽)的多种设置方式----不错
原文网址:http://orgcent.com/android-edittext-ems-layout-minwidth-maxheight/ EditText大小的设置有多种方式,要想对每种方式运用 ...