网上查了一下如下:
方法一:
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; // 去掉边线
网友评论