iOS 去掉UISearchBar灰色背景

有以下两种方法,个人推荐第二种:

(1)

```

floatversion = [[[UIDevicecurrentDevice]systemVersion]floatValue];

if(version == 7.0) {

_searchBar.backgroundColor= [UIColorclearColor];

_searchBar.barTintColor= [UIColorclearColor];

}else{

for(inti =  0 ;i <_searchBar.subviews.count;i++){

UIView* backView =_searchBar.subviews[i];

if([backViewisKindOfClass:NSClassFromString(@"UISearchBarBackground")] ==YES) {

[backViewremoveFromSuperview];

[_searchBarsetBackgroundColor:[UIColorclearColor]];

break;

}else{

NSArray* arr =_searchBar.subviews[i].subviews;

for(intj = 0;j

UIView* barView = arr[i];

if([barViewisKindOfClass:NSClassFromString(@"UISearchBarBackground")] ==YES) {

[barViewremoveFromSuperview];

[_searchBarsetBackgroundColor:[UIColorclearColor]];

break;

}

}

}

}

}

```



(2)

```

floatversion = [[[UIDevicecurrentDevice]systemVersion]floatValue];

if([_searchBarrespondsToSelector:@selector(barTintColor)]) {

floatiosversion7_1 = 7.1;

if(version >= iosversion7_1)        {

[[[[_searchBar.subviewsobjectAtIndex:0]subviews]objectAtIndex:0]removeFromSuperview];

[_searchBarsetBackgroundColor:[UIColorclearColor]];

}

else{//iOS7.0

[_searchBarsetBarTintColor:[UIColorclearColor]];

[_searchBarsetBackgroundColor:[UIColorclearColor]];

}

}

else{

//iOS7.0以下

[[_searchBar.subviewsobjectAtIndex:0]removeFromSuperview];

[_searchBarsetBackgroundColor:[UIColorclearColor]];

}


```


转载自:http://blog.csdn.net/wjh15085872684/article/details/51604558

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容