Google Place Packer搜索栏文本颜色不更改iOS Swift



这是我的代码
 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]

最新更新