Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search Bar background color Gray ios7

I am currently working on an app that worked fine until ios7 came along. The search bar used to be transparent and blended into the blue background of the navigation bar. Now that I am working in ios7, the nav bar is blue, however the search bar has a gray background to it. How do I make it blue or transparent?

Here is an image:

enter image description here

like image 450
Freddy Avatar asked Oct 03 '13 21:10

Freddy


3 Answers

Try this:

if(IOS_7)
{
    self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
}
like image 120
Quang Hà Avatar answered Nov 09 '22 20:11

Quang Hà


You can set "Bar Tint" to "Clear Color" in Interface Builder (.xib):

enter image description here

It can also be done in code:

self.searchBar.barTintColor = [UIColor clearColor];
like image 37
David Douglas Avatar answered Nov 09 '22 22:11

David Douglas


To make it a flat color, you simply need to remove the UISearchBarBackground view.

I created a recursive method to properly clean the search bar.

- (void) removeUISearchBarBackgroundInViewHierarchy:(UIView *)view
{
    for (UIView *subview in [view subviews]) {
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            [subview removeFromSuperview];
            break; //To avoid an extra loop as there is only one UISearchBarBackground
        } else {
            [self removeUISearchBarBackgroundInViewHierarchy:subview];
        }
    }
}

You can simply send your search bar to the method and change the color afterward.

[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
self.searchDisplayController.searchBar.backgroundColor = yourUIColor;
like image 6
Gabriel Cartier Avatar answered Nov 09 '22 21:11

Gabriel Cartier