ios - 将文本添加到 GMSMapView 而不调整大小

标签 ios swift google-maps-sdk-ios

我需要向我的 GMSMapView 添加一些文本字符串,可以像之前在这里提出的问题的解决方案一样执行此操作(从 UILabel 获取 UIImage,然后将带有该图像的 GMSGroundOverlay 作为图标添加到 GMSMapView),但我需要添加文本,这不会当用户更改 map 缩放时调整大小。

enter image description here enter image description here

您可以看到,当用户更改 map 的缩放时,我的标签也会更改字体大小,但我需要添加标签,该标签看起来与街道名称相同 - 缩放时无需调整大小。如何制作?

最佳答案

根据您的要求,为什么不使用 GMSMarker 而不是 GMSGroundOverlay

这段代码对我有用

- (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

添加标签标记

UILabel *label = [UILabel new];
label.text = @"Job";

label.opaque = NO;

label.font = [UIFont fontWithName: @"Arial" size: 14];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;

label.layer.borderWidth = 2.0;
label.layer.borderColor = [UIColor blackColor].CGColor;
label.layer.masksToBounds = true;

label.layer.cornerRadius = 50;
label.frame = CGRectMake(0, 0, 100, 100);

GMSMarker *title = [GMSMarker markerWithPosition:centerPosition];
title.icon = [self imageWithView:label];
title.map = mapView;

关于ios - 将文本添加到 GMSMapView 而不调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45398656/

相关文章:

ios - 使用 Mac Hotspot 进行移动设备的自动化测试

ios - Typhoon DI 的 Storyboard集成

ios - 如何在谷歌地图 ios 中标记 map 标记

iOS渲染输入按钮不正确

ios - 导航栏颜色 ios 7

xcode - 如何使用 xcode7 更改我的移动应用程序的名称

ios - 允许一个 Controller 能够旋转到横向模式

ios - 如何找到Google Maps Path的长度

IOS 谷歌地图防滑边界

ios - 我对这个练习的解决方案似乎太简单了;提示?