Google地方选择器搜索栏文本颜色不更改iOS Swift

iOS*_*iOS 1 ios google-places-api swift3

这是我的代码请查看我设置颜色的第4行,但它会显示错误

 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)
Run Code Online (Sandbox Code Playgroud)

Raj*_*r R 5

试试这个.

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