1

我在我的应用程序中使用 GMSPlacePicker。它有一个非常简单的 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) {

}];

它会自动从当前显示的 ViewController 中呈现自己。还有一个搜索功能,允许用户使用文本搜索该地点。

但是,我的应用程序主题是黑色的,并且我使用 UIAppearance 代理设置了导航栏颜色:

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

这会导致搜索出现问题,因为导航栏背景是黑色的,因此无法看到搜索文本。

在此处输入图像描述

我也尝试过使用这里建议的 UIAppearance 代理,但没有效果。

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

2 回答 2

2

这帮助了我:

[[UISearchBar appearance] setBarStyle:UIBarStyleBlack]
于 2016-05-06T15:06:52.607 回答
0

我在使用 Google Maps API 时遇到了同样的问题,并通过以下代码行找到了我的解决方案:

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

在您创建 Google Maps API 类的对象之后和呈现该类之前添加上面的行。

上面接受的答案也适用于这种情况并且是可观的,但是该代码行将使搜索栏中的文本默认为黑色。

通过使用我的答案,可以将文本颜色更改为 iOS 中可用的任何自定义颜色。

于 2017-02-22T09:40:50.170 回答