Browsed the documentation and I couldn't find anything to change the color of UISearchBar. Does anybody know how to change it? There isn't any textColor property :/
Thx
Browsed the documentation and I couldn't find anything to change the color of UISearchBar. Does anybody know how to change it? There isn't any textColor property :/
Thx
For iOS11, I found this worked:
After setting the
searchController
into thenavigationItem
, the search text was black on black. To make it white, I had to do:It was the only thing that worked for me. My app has a transparent navigation bar to let the background gradient show through, and I am guessing the SearchBar takes on that appearance since my appearance settings for
UISearchBar
were largely ignored with one exception:This made the Cancel button and the text insertion cursor red. The placeholder text was light gray.
Note that:
UISearchBar.appearance().barStyle = .blackTranslucent
did not work - it had to be set on the instance. This also had no visible effect on the search bar (it was still transparent like the navigation bar); it just made the search text white.After setting the
searchController
in thenavigationItem
for iOS 11, I found that attempting to set thetextColor
viaUIAppearance
for anyUITextField
within aUISearchBar
had no affect, but a custom appearance property that simply called the regulartextColor
worked just fine.And then use as follows:
P.S. The same trick helped me color the seemingly inaccessible labels of
UIDatePicker
andUIPickerView
Here's a cleaner approach:
I suspect you could use techniques described in this post
Modifying the code presented there slightly, you subclass UISearchBar:
Then in your implementation:
I haven't tested either the original post's code or this code, but looks like it ought to work. -wkw
appearanceWhenContainedIn is deprecated in iOS 9 , so we have to use below method for iOS 9 and above.