IOS Swift 3 - Has anyone managed to implement the new GMSPlacePickerViewController Google Place API with UI?
I am currently rebuilding an application using the PlacePicker from the Google Place API to get data that the user can add to my map.
I have used GMSPlacePicker in the past, which is now deprecated since Google released their API Place 2.3. So I am currently trying to migrate to a new way of using the API via the GMSPlacePickerViewController , which according to google can be implemented using the UI.
From google documentation :
Since the place collector is a regular controller, it can be displayed in any way you want. For example, in full screen full screen mode, navigation stack or even as part of the user interface of a custom application .
I was able to make the GMSPlacePickerViewController part of my wider navigation controller that allows me to go back and forth inside the place picker screens, however I have not yet been able to customize the search bar UI we see in the third one in the image below.
Question:
The text inside the SearchBar is black and I want to make it white, but I don't know how to access the searchBar and its properties, since everything seems to be abstracted within the framework. I would also like to change the Select Location heading (Figure 2) to something smaller.
Any thoughts? thanks in advance
source to share
You can change this with proxies UIAppearance
as described in Use UIAppearance protocol ( GMSPlacePickerViewController
used GMSAutocompleteViewController
internally).
// Color of typed text in the search bar.
NSDictionary *searchBarTextAttributes = @{
NSForegroundColorAttributeName: lightGray,
NSFontAttributeName : [UIFont systemFontOfSize:[UIFont systemFontSize]]
};
[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]]
.defaultTextAttributes = searchBarTextAttributes;
source to share
Andrew's answer worked for me at the end. I converted it to Swift 3.0 for those who might need it in the future. You can simply add the following to your AppDelegate.swift file in doneFinishLaunchingWithOptions :
Also searchBarTextAttributes is a dictionary so feel free to add additional properties there to customize even more.
let searchBarTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UITextField.appearance(whenContainedInInstancesOf:[UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
source to share