答案 0 :(得分:15)
您可以覆盖搜索栏的drawRect。通过将“UISearchBarBackground”视图设置为0的alpha,它将绘制您设置的扁平色调颜色。例如,在您的App Delegate中添加以下内容:
@implementation UISearchBar( CustomBackground )
- (void)drawRect:(CGRect)rect
{
// Find the UISearchBarBackground view and set it's alpha to 0 so we get a "flat"
// search bar.
for( UIView *subview in self.subviews )
{
if( [subview isKindOfClass:NSClassFromString( @"UISearchBarBackground" )] )
{
[subview setAlpha:0.0F];
break;
}
}
}
@end
答案 1 :(得分:2)
_tempSearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(44, 0, 320 - 44, 43)];
_tempSearchBar.barStyle=UIBarStyleDefault;
_tempSearchBar.placeholder=@"搜索";
for( UIView *subview in _tempSearchBar.subviews )
{
if( [subview isKindOfClass:NSClassFromString( @"UISearchBarBackground" )] )
{
UIView *aView = [[UIView alloc] initWithFrame:subview.bounds];
aView.backgroundColor = [UIColor greenColor];
// [subview setAlpha:0.0f];
[subview addSubview:aView];
break;
}
}
答案 2 :(得分:0)
我这样做了:
[toolbar setTintColor:[UIColor greenColor]];
得到了这个:
这就是你要找的东西吗?