UISearchBar背景色修改

2016-05-12  本文已影响287人  天空没有太阳

网上查了一下如下:

方法一:
UISearchBar *seachBar=[[UISearchBar alloc] init];
//修改搜索框背景
seachBar.backgroundColor=[UIColor clearColor];
//去掉搜索框背景
//1.
[[searchbar.subviews objectAtIndex:0]removeFromSuperview];
//2.
for (UIView *subview in seachBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
//3自定义背景
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"40-di.png"]];
[mySearchBar insertSubview:imageView atIndex:1];
[imageView release];

第一第二方法试了并没有用,解决如下:

self.searchBar.barTintColor = [UIColor redColor]; // 修改背景色
self.searchBar.searchBarStyle =UISearchBarStyleMinimal;  // 去掉边线
上一篇 下一篇

猜你喜欢

热点阅读