views:

1158

answers:

3

The UISearchBar in my UITableView header is the strong color.

The TableSearch uses the more subtle code, but I'm not sure how it's doing it. I've looked at the TableSearch example code. Specifically, I don't see tintColor being used anywhere in this example. I don't see opacity or alpha used, either.

How does the TableSearch example do this? Can anyone explain it?

+3  A: 

You can set the UISearchBar to any color you like using:

self.mySearchBar.tintColor = [UIColor colorWithRed:153/255.0 green:102/255.0 blue:51/255.0 alpha:1.0];

In this example the first number in the fractions are the RGB values. Just find the RGB color you want and fill in the values here.

Jonah
+1  A: 

According to the documentation, there is a tintColor property on the UISearchBar class.

In the TableSearch example the search bar is defined and loaded in the MainView.xib. If you want to change its tintColor or style, just do it in the xib and it will be loaded into the application.

Adam Woś
What I'm trying to figure out is how Apple's code manages it. There's no tintColor in the sample code anywhere.
Steven Fisher
There isn't, because the bar in the example does not have a tintColor - it uses the default (=nil) and renders the bar with the style defined (`UIBarStyle barStyle = UIBarStyleDefault`).
Adam Woś
I guess the answer, then, is that the table view automatically tints the attached search bar? Good enough. Thanks.
Steven Fisher
A: 

I thought i'd mention that the alpha value for the tint colour does not seem to do anything. It always displays as alpha 1.0 value, and in interface builder, it does not let you adjust the opacity value.

Rob