Add Labeltext on Mkannotation image

南笙酒味 提交于 2019-12-24 03:07:13

问题


I am using a MKMapView with custom placeMark, it has a NSString value and i'll like to add it as label to the mkannotationview image.

- (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;}

Which would be the best way to get it, I tried to add a label to the image but I had problems with the CGRect and I get nothing, any idea how to make it

Thanks!


回答1:


The annotation view draws the image? In that case I would add a UILabel as a subview.

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


来源:https://stackoverflow.com/questions/6175670/add-labeltext-on-mkannotation-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!