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)
答案 0 :(得分:5)
试试这个。
if #available(iOS 9.0, *) {
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSForegroundColorAttributeName: UIColor.green]
} else {
// Fallback on earlier versions
}
答案 1 :(得分:0)
此版本适用于最新的Swift版本
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white] as [String:Any]