自定义UISearchBar
先上系统默认的UISearchBar,然后用KVO修改
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:_topView.bounds];
searchBar.placeholder = @"请输入您要搜索的商品";
效果为:

①将取消按钮cancle改为“取消”
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
searchBar.showsCancelButton = YES;
for(UIView *view in [[[searchBar subviews] objectAtIndex:] subviews]) {
if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
UIButton * cancel =(UIButton *)view;
[cancel setTitle:@"取消" forState:UIControlStateNormal];
[cancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cancel.titleLabel.font = [UIFont systemFontOfSize:];
}
}
}
效果为

②修改searchbar背景色
UIView *backView = [[UIView alloc]initWithFrame:searchBar.bounds];
backView.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
[searchBar insertSubview:backView atIndex:];

③设置searchbar输入框背景颜色及删减符号mode
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
searchField.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.1];
searchField.clearButtonMode = UITextFieldViewModeNever;


④修改searchbar输入框的文字和占位符文字颜色
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
searchField.textColor = [UIColor whiteColor];
[searchField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

⑤修改放大镜图标
UITextField *searchField = [searchBar valueForKey:@"_searchField"];
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_search"]];
iconView.frame = CGRectMake(, , , );
searchField.leftView = iconView;

自定义UISearchBar的更多相关文章
- iOS 如何自定义UISearchBar 中textField的高度
iOS 如何自定义UISearchBar 中textField的高度 只需设置下边的方法就可以 [_searchBar setSearchFieldBackgroundImage:[UIImage i ...
- 新浪微博客户端(5)-自定义UISearchBar
iOS自带的UISearchBar有很多限制,我们可以使用UITextField做出一个类似于SearchBar的效果. //===================================== ...
- 自定义UISearchBar外观
1. 设置背景色 我以白色的背景色为例,下面看看代码: //1. 设置背景颜色 //设置背景图是为了去掉上下黑线 self.customSearchBar.backgroundImage = [[UI ...
- iOS 将navigationItem.titleView设置为自定义UISearchBar (Ficow实例讲解)
这篇文章可以解决以下问题: 1.将searchBar设置为titleView后,无法调整位置的问题 : 2.searchBar的背景色无法设置为透明色的问题: 3.searchBar输入框内用户输入的 ...
- iOS开发UI篇 -- UISearchBar 属性、方法详解及应用(自定义搜索框样式)
很多APP都会涉及到搜索框,苹果也为我们提供了默认的搜索框UISearchBar.但实际项目中我们通常需要更改系统默认搜索框的样式.为了实现这一目标,我们需要先搞懂 UISearchBar 的属性及方 ...
- UISearchBar 自定义处理
首先通过 KVC 获取到内部的 textField, 然后自定制处理 UITextField *searchField = [searchBar valueForKey:@"searchFi ...
- IOS开发之UISearchBar自定义外观
MySearchBar.h如下: @interface MySearchBar : UISearchBar - (void)layoutSubviews; @end MySearchBar.m如下 ...
- UIsearchBar 自定义样式
对于修改输入框圆角 的需求, 可以通过修改搜索框背景图片的方式设置. - (void)setSearchFieldBackgroundImage:(nullable UIImage *)backgro ...
- iOS数字键盘自定义按键
UIKeyboardTypeNumberPad 数字键盘自定义按键 最近做一个搜索用户的功能,这里使用了UISearchBar.由于搜索的方式只有手机号码,所以这里的键盘要限制为数字输入,可以这么做: ...
随机推荐
- Jmeter plugin jp@gc - PerfMon Metrics Collector
Jmeter由于是开源工具,所以目前有很多插件可以供使用,最简单的方法是先把Plugin Manager安装了 下载地址:https://jmeter-plugins.org/wiki/Plugins ...
- where 子句中使用通配符
模糊匹配 ------------------------模糊匹配----------------- '[1-9]'.'[a-z]'.'[^4]' select * from student wher ...
- 习课的redis配置记录
<!-- redis begin --> <dependency> <groupId>redis.clients</groupId> <artif ...
- shell 判断文件是否存在
举例 #!/bin/sh myFile="/var /log/httpd/access.log" if [ ! -e "$myFile" ]; then tou ...
- nginx 配置全站404(百度闭站保护)
在百度站长里申请闭站保护时,需要全站404.可能过nginx配置实现 location / { #root html; #index index.html index.htm; retur ...
- ArcGIS api fo silverlight学习一(silverlight加载GeoServer发布的WMS地图)
最好的学习资料ArcGIS api fo silverlight官网:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm 一. ...
- 在SQLSERVER中快速有条件删除海量数据技巧推荐
解释: 如果你的硬盘空间小,并且不想设置数据库的日志为最小(因为希望其他正常的日志希望仍然记录),而且对速度要求比较高,并清除所有的数据建议你用turncate table1,因为truncate 是 ...
- sea.js 入门
上个月学了 require.js 现在顺便来学学 sea.js. 对比下这两种的区别,看自己喜欢哪个,就在接下来的项目中去使用它吧. seajs中的所有 JavaScript 模块都遵循 CMD 模块 ...
- css之页面三列布局
左右两边宽度固定,中间自适应 第一种方法:左右两边绝对定位 html代码 <div class="left"></div> <div class=&q ...
- 9.5.8 Optimizing InnoDB Disk I/O
如果你数据库设计以及sq操作都是最佳实践,但是你数据库仍然被较重的io活动拖累的较慢,那么试一试看看top或者windows的任务管理器,cpu使用率和工作量低于70%,那么或许是您的硬盘较慢. 1 ...