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

你可能感兴趣的:(iOS 去掉UISearchBar灰色背景)