您的位置:首页 > 产品设计 > UI/UE

iOS 6/7 UISearchBar的背景色设置

2016-01-25 15:13 435 查看
在iOS7中,UISearchBar的子视图变成一个UIView,所以原来的方法不管用了,但是看了一下文档,在iOS7中新增了一个barTintColor的属性,我们可以设置barTintColor为clearColor

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if ([ searchBar respondsToSelector : @selector (barTintColor)]) {
float  iosversion7_1 = 7.1 ;
if(version >= iosversion7_1)
{
//iOS7.1
[[[[searchBar.subviews objectAtIndex : 0 ] subviews] objectAtIndex:0] removeFromSuperview];
[ searchBar setBackgroundColor:[ UIColor clearColor]];
}
else
{
//iOS7.0
[ searchBar setBarTintColor:[UIColor clearColor]];
[ searchBar setBackgroundColor:[UIColor clearColor]];
}
}

else

{
//iOS7.0 以下
[[searchBar.subviews objectAtIndex:0] removeFromSuperview ];
[searchBar setBackgroundColor:[UIColor clearColor]];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: