Inder_iOS
Inder_iOS

Reputation: 1656

Google Place Picker Search Bar text Color not Change iOS Swift

This is my Code Please review 4th line where i set color but it will show me Error

 let autocompleteController = GMSAutocompleteViewController()
    autocompleteController.delegate = self
    UINavigationBar.appearance().tintColor = UIColor.white
    UISearchBar.appearance.textField.setTextColor = UIColor.red
    UISearchBar.appearance().barStyle = UIBarStyle.default
    self.present(autocompleteController, animated: true, completion:nil)

Upvotes: 1

Views: 1439

Answers (2)

Mitesh Dobareeya
Mitesh Dobareeya

Reputation: 1020

This one is worked for latest swift version

UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white] as [String:Any]

Upvotes: 0

RajeshKumar R
RajeshKumar R

Reputation: 15758

Try this.

if #available(iOS 9.0, *) {
  UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSForegroundColorAttributeName: UIColor.green]
  } else {
  // Fallback on earlier versions
}

Upvotes: 5

Related Questions