美文网首页
UISearchBar背景色修改

UISearchBar背景色修改

作者: 天空没有太阳 | 来源:发表于2016-05-12 13:55 被阅读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;  // 去掉边线

相关文章

网友评论

      本文标题:UISearchBar背景色修改

      本文链接:https://www.haomeiwen.com/subject/kevurttx.html