1

In my AppDelegate, I have customized my UISearchBars in my app (i have a few), so they would match the app colors and such. (The app color isa sort of teal). My code is as follows:

// Set appearance of UISearchBar for the app appearance
        UISearchBar.appearance().tintColor = UIColor.whiteColor()

        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = appColor
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).font = UIFont.init(name: "AvenirNext-Medium", size: 17)
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()
        UISearchBar.appearance().searchBarStyle = UISearchBarStyle .Minimal
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).attributedPlaceholder = NSAttributedString.init(string: "Search...", attributes: [NSForegroundColorAttributeName : UIColor.whiteColor()])
        UISearchBar.appearance().setImage(UIImage(named: "searchIcon"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState .Normal)

After all this, this is what happens on first launch:

first launch

The text is still gray, even though I set it to be white in the AppDelegate.

When I click on the search bar:

clicked

And when I hit cancel:

after cancel hit

This is what it is supposed to look like. I'm not sure why the text is gray before a user interaction. Does anyone have a solution?

Minebomber
  • 1,209
  • 2
  • 12
  • 35
  • Have you tried [this](http://stackoverflow.com/questions/1407833/uisearchbar-text-color/28183058#28183058)? – saagarjha May 09 '16 at 04:02

1 Answers1

2

You can try

UILabel.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()

please see if that works

Priya
  • 1,359
  • 6
  • 21
  • 41
Nat
  • 36
  • 5