Dan Dan - 4 months ago 29
iOS Question

Setting tint color for embedded UISearchbar in Navigation bar

I have an app that has a blue tint theme to the entire UI. I also have an embedded search bar in the Navigation Bar on my initial view. My button text color for the app is white and declare that in the app delegate using:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];


Problem is that this causes the embedded search bar to hide the cursor when it is selected because of the white tint affecting the search bar. I have tried to specifically set the tint of the search bar to [UIColor blueColor] using two methods but have had no luck. The two ways I have tried to refrence the UISearch bar are:

[self.navigationController.searchDisplayController.searchBar setTintColor:[UIColor blueColor]];


and

[searchBar setTintColor:[UIColor blueColor]]


The searchBar should be referenced properly.

Nothing I do to these outlets affect the embedded search bar at all.

Answer

Had the same problem. Solved it by using this code after embedding the search bar into navigation bar.

    self.navigationItem.titleView.tintColor = [UIColor blueColor];

Probably not the best solution, but it works.