更改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, 在前一个快结束的时候,另一个显示.然而点 ...
随机推荐
- hdu2412(树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2412 题意:给定一棵关系树 , 从中选择一些点 , 使这些点均不存在亲子关系 , 最多能取多少个点 , ...
- Android---App Widget(一)
本文译自:http://developer.android.com/guide/topics/appwidgets/index.html App Widgets是一些较小的应用程序窗口,它们能够被嵌入 ...
- Javascript异步数据的同步处理方法
数据处理方法封装 var DataWatch=(function(){ var gWatch={},cursor= 0,callback_key = 'callback',gMap={}; var c ...
- poj 3280 Cheapest Palindrome ---(DP 回文串)
题目链接:http://poj.org/problem?id=3280 思路: dp[i][j] :=第i个字符到第j个字符之间形成回文串的最小费用. dp[i][j]=min(dp[i+1][j]+ ...
- php 禁止 URL 直接访问 php文件
通过判断访问来源来实现. $fromurl="http://www.111.com/index.php"; //只能从这个地址访问 if( $_SERVER['HTTP_REFER ...
- Java--调试--单步调试,断言,单元测试
单步调试:主要查看变量内容的变化 1.设置断点位置,设置在可能出现问题的代码 2.以Debug as方式运行 程序 3.F5 --> step into 进入方法内部进行调试 F6 ...
- 关于bind函数和connect函数的测试结论
1. 一般客户端不用绑定,系统给你自动分配(有些ip不是固定的,bind也不是一个好方法):而服务器需要绑定,因为需要给客户端一个众所周知的固定的地址: 2. 关于bind错误,可以用WSAGetLa ...
- 13-7-5 android Tabhost功能实现
开始使用了一个Activity做界面切换,采用visible.gone写法,感觉太麻烦了. layoutHousehold.setVisibility(View.GONE); layoutCamera ...
- cocos2d-x3.0 相对布局(一)
2dx相对布局和Android非常类似.假设前完成Android它应该是easy入门. Size widgetSize = Director::getInstance()->getWinSize ...
- 白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》串行4(场景变化)
作为一个真正的利用价格值应用,首先,你应该至少有两页,通过切换页面来实现很多其他互动.比如手机人人网,首先,打开后进入登录页面,将有登录后,新的东西.然后拉左侧面板.你可以看到相册.私人信息.像其他应 ...