2011-05-30 54 views
2

我正在使用帶有自定義placeMark的MKMapView,它有一個NSString值,我想將它作爲標籤添加到mkannotationview圖像。在Mkannotation圖像上添加Labeltext

- (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問題,我什麼也沒得到,任何想法如何使它

謝謝!

回答

4

註解視圖繪製圖像?在這種情況下,我會添加一個UILabel作爲子視圖。

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

是的註釋繪製圖像,我有問題找到x,y爲initWithFrame,寬度和高度我有它的image.size屬性。 – Uris 2011-05-30 11:44:27

+0

這很棒,我定義了一個上下文,它效果很棒!謝謝!! – Uris 2011-05-31 08:07:48

+0

我有一個名爲CustomPin的類,它採用MKAnnotation。我想在註釋本身中放入一個數字。我已經爲課堂添加了一個UILabel,並計劃以這種方式接近它。這是正確的方式嗎? – Mihado 2016-03-03 17:26:56