更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底
转载请标明出处:http://blog.csdn.net/android_ls/article/details/39993433
測试的手机IOS系统版本为:6.1.3,实现过程例如以下:
1、加入UISearchBar到父View
_searchBar = [[UISearchBar alloc]init];
_searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, kSeachBarH);
_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_searchBar.delegate = self;
_searchBar.placeholder = @"请输入姓名、公司名称、公司产品名称";
[self.view addSubview:_searchBar];
2、改动搜索框背景
UIImage *img = [UIImage resizedImage:@"find_bg.png"];
[_searchBar setBackgroundImage:img];
3、改动搜索输入框内左側的指示图标
[_searchBar setImage:[UIImage resizedImage:@"ic_search.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
4、改动搜索输入文本的背景
[_searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"login_btn_input_side.png"] forState:UIControlStateNormal];
注:对于设计人员提供的搜索输入文本的背景。若提供的是一个圆角的小方块,按常理我们会使用拉伸图片的中间部分的方法,经測试显示效果例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW5kcm9pZF9scw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" width="320" height="480" alt="">
若让设计人员又一次提供一张固定高度的图片(比方高是60),当做搜索输入文本的背景。效果图例如以下:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYW5kcm9pZF9scw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" width="320" height="480" alt="">
5、改动UISearchBar右側的取消button文字颜色及背景图片
#pragma mark 搜索框的代理方法,搜索输入框获得焦点(聚焦)
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES]; // 改动UISearchBar右側的取消button文字颜色及背景图片
for (UIView *searchbuttons in [searchBar subviews]){
if ([searchbuttons isKindOfClass:[UIButton class]]) {
UIButton *cancelButton = (UIButton*)searchbuttons;
// 改动文字颜色
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; // 改动button背景
[cancelButton setBackgroundImage:[UIImage resizedImage:@"login_btn_login.png"] forState:UIControlStateNormal];
[cancelButton setBackgroundImage:nil forState:UIControlStateHighlighted];
}
}
}
注:改动取消button文字颜色及背景图片的代码片段,一定要放到取消button会显示代理方法中改动,否则遍历找不着呀,那就改动不了了。
版权声明:本文博主原创文章,博客,未经同意不得转载。
更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底的更多相关文章
- IOS 纯代码添加 Button Image Label 添加到自定义View中
@interface ViewController () /**获取.plist数据*/ @property (nonatomic,strong) NSArray *apps; @end @imple ...
- iOS之自动调节输入文本框的高度
//自动调节输入文本框的高度 - (void)textViewDidChange:(UITableView *)textView{ float height; if ([[[UIDevice curr ...
- iOS案例:读取指定txt文件,并把文件中的内容输出出来
用到的是NSString中的initWithContentsOfFile: encoding方法 // // main.m // 读取指定文件并输出内容 // // Created by Apple ...
- iOS开发UI篇—Button基础
iOS开发UI篇—Button基础 一.简单说明 一般情况下,点击某个控件后,会做出相应反应的都是按钮 按钮的功能比较多,既能显示文字,又能显示图片,还能随时调整内部图片和文字的位置 二.按钮的三种状 ...
- iOS设备下添加button的按下效果
在触屏上, button的按下效果用:active触发, 但是我发现iOS设备上:active效果并没有生效. :active pseudo-class doesn't work in mobile ...
- 【好程序员笔记分享】——iOS开发之使用TextField作为搜索框
-iOS培训,iOS学习-------型技术博客.期待与您交流!------------ iOS开发之使用TextField作为搜索框 今天给大家带来一个新的技巧,比如平时我们要使用代码创建一 ...
- iOS开发基础篇-Button基础
一.简单介绍 UIButton 的功能:响应用户操作.显示文字.显示图片.调整内部图片和文字的位置. 二. UIButton 的状态 UIControlStateNormal :普通状态,为默认情 ...
- iOS开发之三个Button实现图片无限轮播(参考手机淘宝,Swift版)
这两天使用Reveal工具查看"手机淘宝"App的UI层次时,发现其图片轮播使用了三个UIButton的复用来实现的图片循环无缝滚动.于是乎就有了今天这篇博客,看到“手机淘宝”这个 ...
- 【IOS】自定义可点击的多文本跑马灯YFRollingLabel
需求 项目中需要用到跑马灯来仅展示一条消息,长度合适则不滚动,过长则循环滚动. 虽然不是我写的,但看了看代码,是在一个UIView里面放入两个UILabel, 在前一个快结束的时候,另一个显示.然而点 ...
随机推荐
- FZU 1686(重复覆盖)
题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31370 题意:用尽量少r*c的小矩形覆盖大矩形n*m中的所有1,将 ...
- UVA 10820 Send a Table euler_phi功能
除1,1其他外国x,y不等于 为 x<y 案件 一切y有phi(y)组合 F[x]= phi(i) 2<=i<=x 结果为 2*F[x]+1 Problem A Send a Tab ...
- SharedPreferences共享优先存储的详细解析和原理
共享优先存储: publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setCont ...
- oracle数据库恢复与备份
一.oracle数据库恢复 1.恢复刚才删除的一条数据 delete from emp e where e.empname='SMITH' select * from flashback_transa ...
- Core 1.0中的管道-中间件模式
ASP.NET Core 1.0中的管道-中间件模式 SP.NET Core 1.0借鉴了Katana项目的管道设计(Pipeline).日志记录.用户认证.MVC等模块都以中间件(Middlewar ...
- hdu3873 有约束条件的最短路
题目大意:美国佬打算入侵火星,火星上有n个城市,有些城市可能受其他城市保护, 如果i城市受j城市保护,那么你必须先攻占j城市才能再攻占i城市,问你攻占城市n的最短时间是多少. 数据解释: 给定t, 表 ...
- 设计模式C++达到 3.抽象工厂
简单工厂模式和工厂模式 要求 同类型的产品子类有共同的方法.这限制了产品子类的扩展.抽象工厂能client它提供了一个接口,它是client而不必指定产品的详细信息.创建多个产品系列产品对象.在归为一 ...
- 关于读style元素定义样式表兼容性
<span style="font-size:18px;"></span><pre name="code" class=" ...
- ASP.NET WebForm / MVC 源码分析
浏览器 Url:https//localhost:6565/Home/Index ,https//localhost:6565/WebForm1.aspx,请求服务器(构建请求报文,并且将请求报文发送 ...
- HTML5管理与实际历史的分析(history物)
HTML5新进入历史的管理,更新history对象允许国家的经营历史更方便. 在现代Web应用.用户"前进"和"退却"button切换历史页面.这使得新的页码不 ...