UISearchbar设置相关总结
2016-04-06 18:56
453 查看
去掉输入框后面的背景框
突然有一天发现searcher.backgroundColor = [UIColor clearColor];不管用了,那么,,,,又是一顿在网上找,,os系统升级到7.1后,原来在7.0下显示正常的UISearchbar现在又出现问题了。究其原因,是由于UISearchbar的subview又做修改了。
float version = [[[
UIDevice
currentDevice ] systemVersion ]
floatValue ];
if ([ mySearchBar respondsToSelector :
@selector (barTintColor)]) {
float iosversion7_1 =
7.1 ;
if (version >= iosversion7_1)
{
//iOS7.1
[[[[ mySearchBar . subviews objectAtIndex : 0 ] subviews ] objectAtIndex :
0 ] removeFromSuperview ];
[ mySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
else
{
//iOS7.0
[ mySearchBar setBarTintColor :[ UIColor clearColor ]];
[ mySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
}
else
{
//iOS7.0
以下
[[ mySearchBar . subviews objectAtIndex : 0 ] removeFromSuperview ];
[ mySearchBar setBackgroundColor :[ UIColor clearColor ]];
}
修改searchBar的输入框背景色
7.0以前:for (UIView *subView
in _searchBar.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
subView.backgroundColor = RGBColor(19,
115, 209);
}
}
7.0及以后:
// 经测试,
需要设置barTintColor后,
才能拿到UISearchBarTextField对象
_searchBar.barTintColor =
RGBColor(23,
130,
235);
[[_searchBar.subviews[0]
subviews]
lastObject].backgroundColor =
RGBColor(19,
115,
209);
修改输入框的placeholder颜色和输入颜色
//获取searchBar里面的输入框有两种方法// UITextField *searchTextField = [[_searchBar.subviews[0] subviews] lastObject];
UITextField *searchTextField = [_searchBar
valueForKey:@"_searchField"];
searchTextField.backgroundColor =
RGBColor(19,
115, 209);
[searchTextField setValue:[UIColor
whiteColor]
forKeyPath:@"_placeholderLabel.textColor"];
searchTextField.textColor = [UIColor
whiteColor];
相关文章推荐
- master password is required to unlock the password database.the password database will be unlocked d
- 解决requirejs循环依赖问题
- Ionic Cordova IOS build fails after adding media plugin
- iOS UIView之间常用视图之间切换方式
- AlertDialog.Builder setCancelable用法
- iOS UIView视图的图层控制
- Fast guided Filter
- Android酷炫实用的开源框架(UI框架)
- Qt Quick实现的涂鸦程序
- select, iocp, epoll,kqueue及各种I/O复用机制
- UINavigationBar导航栏相关设置
- DWZ (JUI) 教程 navTab 刷新分析
- 前端UI
- VS2013仿真emwin[ucgui]时出现编译错误的解决方法
- Your build settings specify a provisioning profile with the UUID, no provisioning profile was found
- 2016Android UI设计框架&资源
- 如何在ajax请求中设置特殊的RequestHeader
- 跳板机和堡垒机
- IOS开发-UI学习-UIPageControl(页码控制器)的使用
- IOS开发-UI学习-UISlider(滑动条)的使用