UISearchBar and/or UISearchDisplayController color

XCool picture XCool · Jan 17, 2014 · Viewed 9.8k times · Source

UPDATE: Thanks for all the answers. I would like to add that the search bar used is actually a UISearchBar embedded as part of UISearchDisplayController that is set to the a UITableView's header.

I've created a sample project exhibiting this behavior here: https://dl.dropboxusercontent.com/u/3497087/TestSearchDisplayController.zip. I tried setting the barTintColor to blue and black. The most obvious thing is that when setting to black, I get a grayish bar.

I appreciate all answers and ideas, thank you.


I am working on skinning the app that I'm currently working on, and I seem to hit a roadblock with UISearchBar and/or UISearchDisplayController bar color.

The first issue I have revolves around setting the barTintColor for UISearchBar that is attached as a tableview header. I've set it to blackColor in Interface Builder. However, when the app runs, the color doesn't seem to be black, but some sort of gray, with an ugly white line above! I've tried setting this thru code, but that doesn't seem to help too. See screenshots below.

UISearchBar barTintColor set to black in IB

UISearchBar barTintColor when running on simulator

My second question revolves around UISearchDisplayController. I wanted black color when the search display controller takes over the top of the screen. I've tried setting the color code, but the only color that it won't take is, again, black color!

Answer

codercat picture codercat · Jan 17, 2014
 [[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"black"]];

enter image description here

check out your sample project

enter image description here