4

I'm implementing the default GMSAutocompleteViewController for my app. But couldn't find any documentation or guide to change the color of text in the searchController's textField to white. right now it seems black

enter image description here

I want it be white so the text is more visible.

UPDATE : I'm using following code to change to change the 'Cancel' button color to white as well but it's the same.

let autocompleteController = GMSAutocompleteViewController()
autocompleteController.tintColor = .white
N4SK
  • 700
  • 8
  • 25
  • primaryTextColor? from the documentation: https://developers.google.com/places/ios-api/reference/interface_g_m_s_autocomplete_view_controller...https://stackoverflow.com/questions/39912800/gmsautocompleteviewcontroller-ios-how-to-change-the-text-color-in-the-searchbar – RLoniello Dec 07 '17 at 06:03
  • I've tried that before as well as now... same result... @Ercell0 I think its for results that appear below after user types in searchController not the text in searchController's textField. – N4SK Dec 07 '17 at 06:08
  • https://stackoverflow.com/questions/39912800/gmsautocompleteviewcontroller-ios-how-to-change-the-text-color-in-the-searchbar – RLoniello Dec 07 '17 at 06:08
  • That was an old code... but, I've made an update to it in my code (i'm using swift 4)... should I post that as an answer here? @Ercell0 – N4SK Dec 07 '17 at 06:19
  • I'm still not able to get that cancel button to change to white color @Ercell0 – N4SK Dec 07 '17 at 06:20

1 Answers1

4

I used this code :

Swift 2: as mentioned in the comments by @Ercell0

GMSAutocompleteViewController iOS, how to change the text color in the searchBar

Swift 4.0:

let searchBarTextAttributes: [String : AnyObject] = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white, NSAttributedStringKey.font.rawValue: UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes

Swift 4.2. & above:

let autocompleteController = GMSAutocompleteViewController()
let searchBarTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white, NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
N4SK
  • 700
  • 8
  • 25