GMSAutocompleteViewController iOS, how to change the text color in the searchBar [duplicate]

孤人 提交于 2019-12-07 14:08:06

问题


I'm using a GMSAutocompleteViewController and want to change the textColor in the searchBar but can't find a way to do it, I managed to change the some colors but not the searchBar text.

I've tried following code but the color won't change:

        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()

回答1:


For those who are looking for Swift 4 version, following code worked for me in Swift 4 (Xcode 9.4 & iOS 11)

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


来源:https://stackoverflow.com/questions/39912800/gmsautocompleteviewcontroller-ios-how-to-change-the-text-color-in-the-searchbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!