GMSAutocompleteViewController iOS,如何在 searchControllers 中为文本设置不同的颜色?
GMSAutocompleteViewController iOS, How can I get different color for text in searchControllers?
我正在为我的应用实现默认的 GMSAutocompleteViewController。但是找不到任何文档或指南来将 searchController 的文本字段中的文本颜色更改为白色。现在看起来是黑色的
我希望它是白色的,这样文字更显眼。
更新: 我正在使用以下代码将 'Cancel' 按钮颜色也更改为白色,但它是一样的。
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.tintColor = .white
我使用了这段代码:
Swift 2: 正如 @Ercell0
评论中提到的
GMSAutocompleteViewController iOS, how to change the text color in the searchBar
Swift 4.0:
let searchBarTextAttributes: [String : AnyObject] = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white, NSAttributedStringKey.font.rawValue: UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
Swift 4.2。及以上:
let autocompleteController = GMSAutocompleteViewController()
let searchBarTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white, NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
我正在为我的应用实现默认的 GMSAutocompleteViewController。但是找不到任何文档或指南来将 searchController 的文本字段中的文本颜色更改为白色。现在看起来是黑色的
我希望它是白色的,这样文字更显眼。
更新: 我正在使用以下代码将 'Cancel' 按钮颜色也更改为白色,但它是一样的。
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.tintColor = .white
我使用了这段代码:
Swift 2: 正如 @Ercell0
评论中提到的GMSAutocompleteViewController iOS, how to change the text color in the searchBar
Swift 4.0:
let searchBarTextAttributes: [String : AnyObject] = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white, NSAttributedStringKey.font.rawValue: UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
Swift 4.2。及以上:
let autocompleteController = GMSAutocompleteViewController()
let searchBarTextAttributes: [NSAttributedString.Key : AnyObject] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white, NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): UIFont.systemFont(ofSize: UIFont.systemFontSize)]
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes