Changing cursor color on UISearchBar without changing tintColor

Ashish Awaghad picture Ashish Awaghad · Jul 29, 2014 · Viewed 14.3k times · Source

I want my searchBar's tint color to be white (meaning the cancel button be white). The cursor is not visible when the tint color is white. Is there a way to set cursor color separately?

Answer

McFadden picture McFadden · Jul 29, 2014

Set your tint color to the color you want the cancel button to be and then use the UIAppearance Protocol to change the tint color on the text field to be the color you wish the cursor to be. Ex:

[self.searchBar setTintColor:[UIColor whiteColor]];                
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor:[UIColor darkGrayColor]];