这是我的代码
这是我的代码 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)
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)
尝试这个。
if #available(iOS 9.0, *) {
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSForegroundColorAttributeName: UIColor.green]
} else {
// Fallback on earlier versions
}
这是为最新的swift版本
来工作的UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white] as [String:Any]