在Mkannotation图像上添加Labeltext

时间:2011-05-30 11:26:05

标签: objective-c mkannotationview

我正在使用带有自定义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的问题,我什么都没得到,不知道如何制作它

谢谢!

1 个答案:

答案 0 :(得分:4)

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

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