_searchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(15, 70, DeviceWidth-30 - 50, 30)];
_searchBar.barTintColor = Base_Controller_Color;
[self.view addSubview:_searchBar];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version == 7.0)
{
_searchBar.backgroundColor = [UIColor clearColor];
_searchBar.barTintColor = [UIColor clearColor];
}
else
{
for(int i = 0 ;i < _searchBar.subviews.count;i++)
{
UIView * backView = _searchBar.subviews[i];
if ([backView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES)
{
[backView removeFromSuperview];
[_searchBar setBackgroundColor:[UIColor clearColor]];
break;
}
else
{
NSArray * arr = _searchBar.subviews[i].subviews;
for(int j = 0;j<arr.count;j++ )
{
UIView * barView = arr[i];
if ([barView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES)
{
[barView removeFromSuperview];
[_searchBar setBackgroundColor:[UIColor clearColor]];
break;
}
}
}
}
}
iOS 关于searchbar的背景颜色的设置
最新推荐文章于 2020-08-25 15:01:47 发布