Dan Dan -5 years ago 284
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]];


[searchBar setTintColor:[UIColor blueColor]]

The searchBar should be referenced properly.

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download