【问题标题】:Changing search text color in GMSPlacePicker在 GMSPlacePicker 中更改搜索文本颜色
【发布时间】:2016-02-17 08:20:41
【问题描述】:

我在我的应用程序中使用 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];

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

我也尝试按照here 的建议使用 UIAppearance 代理,但没有效果。

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

【问题讨论】:

    标签: ios objective-c google-maps-sdk-ios gmsplacepicker


    【解决方案1】:

    这对我有帮助:

    [[UISearchBar appearance] setBarStyle:UIBarStyleBlack]
    

    【讨论】:

    • 谢谢!这使得文本显示为灰色......这并不完美,但至少我现在可以阅读它。
    【解决方案2】:

    我在使用 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 中可用的任何自定义颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多