I'm using a GMSAutocompleteViewController and want to change the textColor in the searchBar but can't find a way to do it, I managed to change the some colors but not the searchBar text.

I've tried following code but the color won't change:
acController.searchBarController?.searchBar.tintColor = UIColor.whiteColor()
acController.searchBarController?.searchBar.textColor = UIColor.whiteColor()
acController.searchBarController?.searchBar.textField.textColor = UIColor.whiteColor()
acController.searchBarController?.searchBar.textField.tintColor = UIColor.whiteColor()
acController.searchBarController?.searchBar.textField.backgroundColor = UIColor.whiteColor()
acController.searchDisplayController?.searchBar.setTextColor(UIColor.whiteColor())
acController.searchDisplayController?.searchBar.tintColor = UIColor.whiteColor()
// changes the color of the sugested places
acController.primaryTextColor = UIColor.whiteColor()
acController.secondaryTextColor = UIColor.whiteColor()
For those who are looking for Swift4 version, following code worked for me in Swift 4 (Xcode 9.4 & iOS 11)
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white]
For Swift 5
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With