ZeMoon
ZeMoon

Reputation: 20274

Changing search text color in GMSPlacePicker

I am using GMSPlacePicker in my app. It has a pretty simple API:

CLLocationCoordinate2D center = currentLocation.coordinate;
CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(center.latitude + 0.02, center.longitude + 0.02);
CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(center.latitude - 0.02, center.longitude - 0.02);
GMSCoordinateBounds *viewport = [[GMSCoordinateBounds alloc] initWithCoordinate:northEast
                                                                             coordinate:southWest];
GMSPlacePickerConfig *config = [[GMSPlacePickerConfig alloc] initWithViewport:viewport];
_placePicker = [[GMSPlacePicker alloc] initWithConfig:config];

[_placePicker pickPlaceWithCallback:^(GMSPlace *place, NSError *error) {

}];

It automatically presents itself from the ViewController on display at the moment. There is also a search feature which allows the user to search the place using text.

However, my app theme is black in color and I have set the navigation bar color using the UIAppearance proxy:

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTranslucent:NO];

Which causes a problem in search as the search text cannot be seen as the navigation bar background is black in color.

enter image description here

I have also tried using the UIAppearance proxy as suggested here to no effect.

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

Upvotes: 1

Views: 1230

Answers (2)

Er. Vihar
Er. Vihar

Reputation: 1555

I face the same issue while working on Google Maps API and found my solution by the following line of code:

[[UITextField appearanceWhenContainedIn:[<Object of your Google Maps API class(like GMSAutocompleteViewController)>.searchDisplayController.searchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

Add the line above after you make an object of your Google Maps API class and before you present the class.

The accepted answer above will also work for this scenario and is appreciable, but that line of code will make default black color for the text in the search bar.

By using my answer, one can change the text color to any custom color available in iOS.

Upvotes: 0

Pramod
Pramod

Reputation: 56

This helped me:

[[UISearchBar appearance] setBarStyle:UIBarStyleBlack]

Upvotes: 2

Related Questions