【问题标题】:Add Labeltext on Mkannotation image在 Mkannotation 图像上添加 Labeltext
【发布时间】:2011-05-30 11:26:05
【问题描述】:

我正在使用带有自定义 placeMark 的 MKMapView,它有一个 NSString 值,我想将它作为标签添加到 mkannotationview 图像中。

- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(MyPlaceMark *)annotation{

static NSString* AnnotationIdentifier = @"AnnotationIdentifier";

MKAnnotationView* MyView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];

MyView.canShowCallout=YES;
MyView.image = [UIImage imageNamed:@"MyImage.png"];
return MyView;}

这是获得它的最佳方法,我尝试为图像添加标签,但我遇到了 CGRect 问题,我什么也没得到,不知道如何制作它

谢谢!

【问题讨论】:

    标签: objective-c mkannotationview


    【解决方案1】:

    注释视图绘制图像?在这种情况下,我会添加一个 UILabel 作为子视图。

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x,y,width,height)];
    [yourView addSubview:label];
    [label release];
    

    【讨论】:

    • 是的,注释绘制了图像,我在为 initWithFrame 找到 x、y、image.size 属性的宽度和高度时遇到了问题。
    • 太好了,我定义了一个上下文,效果很好!谢谢!!
    • 我有一个名为 CustomPin 的类,它采用了 MKAnnotation。我想在注释本身里面放一个数字。我在课堂上添加了一个 UILabel 并计划以这种方式接近它。这是正确的方法吗?
    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 2011-11-19
    • 2013-07-29
    • 1970-01-01
    • 2021-01-28
    相关资源
    最近更新 更多