I am using google places API for autoComplete widget. I am showing the full screen control in ios 9+ using swift. I am adding a full control as given in the docs.
I have added the code as shown in the docs. Now I want to change the searchBar text color to whiteColor.
So I tried this
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()
But I am not getting the desired behaviour. Below is the screenshot
This has been given in Docs
https://developers.google.com/places/ios-api/autocomplete#use_a_table_data_source
But this is not working. I need help with regarding to this.
You need to create an extension like follwoing:
And change color using following code:
Output is :
Update:
For the change color of searchBar text for the
GMSAutocompleteViewController
you need to do following code:That change the text out put like following image:
And if you wish to change placeholder text and it's color for
searchBar
. You need to do following code:It will be show like:
For swift 4 ios 12
In swift 5:
Use Bellow code for Swift 3
Hope this helps.
You can use UIAppearance protocol to get the appearance proxy for a class which is available in iOS 5.0 and later.
There are actually two ways to customize appearance for objects and to get the appearance proxy for the class.
appearance
.appearanceWhenContainedIn
.You can apply this sample code:
You can also try another option given in this SO post - UISearchBar text color change in iOS 7.
I hope that covers your issue. Happy coding!