views:

115

answers:

2

I saw this post on SO: http://stackoverflow.com/questions/2232016/uisearchbar-solid-color

But no answer was provided.

I would like to know how to apply a solid color to a UISearchBar. I have applied a tintColor but it automatically creates a gradient.

A: 

I did this:

[toolbar setTintColor:[UIColor greenColor]];

And got this:

alt text

Is that what you're looking for?

Dave DeLong
almost, but it doesn't work for a UISearchBar
Sheehan Alam
A: 

You can override the drawRect for the search bar. By Setting the "UISearchBarBackground" view to an alpha of 0, it will paint it the flat tint color you set. For example, in your App Delegate add this:

@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
Terry Blanchard