1

If i add my UISearchBar without referencing it to a UISearchDisplayController, my tintColor is displayed correctly.

UISearchBar with correct tintColor

searchBar.barTintColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];

But if i reference my UISearchBar to a UISearchDisplayController the color seems different...

UISearchBar referenced to a UISearchDisplayController with wrong tintColor

searchBar = [[UISearchBar alloc] init];
[searchBar setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
searchBar.delegate = self;
searchBar.searchBarStyle = UISearchBarStyleProminent;
searchBar.placeholder = @"Buscar restaurantes o platillos";
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;

searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchController.delegate = self;

self.tableView.tableHeaderView = searchBar;

My tintColor settings on my AppDelegate are

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UIToolbar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
self.window.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.backgroundColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];

Besides that also when my UISearchBar is referenced to my UISearchDisplayController and i tap on the search field... on the transition the background of the Status bar is white.

Transition UISearchBar on a UISearchDisplayController

Any ideas?

i'm Using iOS7

Thanks in advance!

4 Answers 4

5

you can set image in searcher. It will work for searchbar.

[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"red"]];
1
  • it worked great, now i'm just trying to find a way to show the same color in the background for the transition.
    – omarc7
    May 7, 2014 at 9:32
1

Try setting the translucent property to no.

[[UISearchBar appearance] setTranslucent:NO];
1

I found that solution working on iOS7+

searchBar.backgroundImage = UIImage()
searchBar.tintAdjustmentMode = UIViewTintAdjustmentMode.Normal
searchBar.barTintColor = Utils.tintColor()
1

For UISearchController in Swift use:

searchController.searchBar.barTintColor = UIColor.whiteColor()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.