如何在地图图钉注释中显示图像?

3 iphone mkmapview

我有一个视图>> subview mkmapview.

在那我想要显示图像....我目前的形象是这样的.替代文字

我希望像这样表现出来

替代文字

我怎样才能做到这一点 ?如何在此anotation中添加图像.

vda*_*bry 7

您正在谈论的图像对应于MKAnnotationView的leftCalloutAccessoryView属性.

从文档中摘录:

leftCalloutAccessoryView要在标准标注气泡的左侧显示的视图.

您可以实现如下方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {

    MKAnnotationView* annotationView = nil;

    MyAnnotation *myAnnotation = (MyAnnotation*) annotation;
    NSString* identifier = @"Pin";
    MKPinAnnotationView* annView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if(nil == annView) {
        annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
    }

    UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LeftIconImage.png"]];
    annView.leftCalloutAccessoryView = leftIconView;

    return annotationView;
}
Run Code Online (Sandbox Code Playgroud)

希望这有帮助,文森特