1
votes

I have a UISearchBar that is added to my view controller in a xib file.

I have the following properties set through Interface Builder:

barStyle = UIBarStyleDefault
searchBarStyle = UISearchBarStyleMinimal
translucent = YES
barTintColor = Clear Color

In code I'm styling the bar with this code, to make the text color white:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

Also in my app delegate didFinishLoading method I have:

 self.window.tintColor = [UIColor whiteColor];

My cancel button in the UISearchBar is a light grey. When I select it it highlights blue, which is jarring as it doesn't fit with any of the other visual elements in the screen. How can I change the button to highlight to a different color? Alternatively I would be fine if the cancel button was white and highlighted to a grey, like my navigation bar buttons do, but I don't know how to change the button color.

I'm targeting iOS7, using Xcode 5.


This answer seems appropriate, but it is having no effect for me https://stackoverflow.com/a/15791136/472344

2

2 Answers

1
votes

Try this in Appdelegate in didFinishLaunchingWithOptions

[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,nil] forState:UIControlStateNormal];
1
votes

Try to set tintColor of the Search Bar. it work for me with target 8.0 xcode 5.

self.searchBar.tintColor = [UIColor blackColor];