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

时间:2017-03-03 06:39:07

标签: ios swift3 google-places-api

这是我的代码请查看我设置颜色的第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)

2 个答案:

答案 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]