gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:16:20 24 4
gpt4 key购买 nike

我需要向我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com