GMSAutocompleteViewController iOS,如何更改searchBar中的文本颜色

我正在使用GMSAutocompleteViewController并想要更改searchBar中的textColor但无法找到方法,我设法更改了一些颜色而不是searchBar文本。

在此处输入图像描述

我试过跟随代码,但颜色不会改变:

acController.searchBarController?.searchBar.tintColor = UIColor.whiteColor() acController.searchBarController?.searchBar.textColor = UIColor.whiteColor() acController.searchBarController?.searchBar.textField.textColor = UIColor.whiteColor() acController.searchBarController?.searchBar.textField.tintColor = UIColor.whiteColor() acController.searchBarController?.searchBar.textField.backgroundColor = UIColor.whiteColor() acController.searchDisplayController?.searchBar.setTextColor(UIColor.whiteColor()) acController.searchDisplayController?.searchBar.tintColor = UIColor.whiteColor() // changes the color of the sugested places acController.primaryTextColor = UIColor.whiteColor() acController.secondaryTextColor = UIColor.whiteColor() 

试试这个代码

 let searchBarTextAttributes: [String : AnyObject] = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont.systemFontOfSize(UIFont.systemFontSize())] UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes 

对于那些正在寻找Swift 4版本的用户,以下代码在Swift 4(Xcode 9.4和iOS 11)中为我工作

 UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white]