How to change background color of UISearchBar in iOS7?

enter image description here

not gray, I want to change color like my uinavigationbar

if I Use this code, that's what comes out

searchBar.backgroundColor = [UIColor redColor];

enter image description here

That is not red color!!! This exact same situation as in background color of navigation bar.


Solution 1:

Need to use:

searchBar.barTintColor = [UIColor redColor];

enter image description here

All thanks!

Solution 2:

Set the background image to a clear image and you're good to go. This is also pre-ios 7 compatible.

searchBar.backgroundImage = [[UIImage alloc] init]
searchBar.backgroundColor = [UIColor redColor];

Solution 3:

If the above solutions don't seem working then make sure that you've set the search bar style to Minimal.

[self.searchDisplayController.searchBar setSearchBarStyle:UISearchBarStyleMinimal];

And for simple searchBar

[self.searchBar setSearchBarStyle:UISearchBarStyleMinimal];

SearchBar Style can also be set from interface builder to Minimal.