0

我有一个 MKPinAnnotationView 并且在我的 viewForAnnotation 方法中,我执行以下操作:

customPinView.image = [UIImage imageNamed:@"blah.png"];

我已将 blah.png 添加到我的资源中(通过将文件拖入)

但我仍然看到股票别针而不是我的形象。难道我做错了什么?这是完整的代码:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString *AnnotationViewID = @"annotationViewID";

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
    }

    annotationView.image = [UIImage imageNamed:@"blah.png"];
    annotationView.annotation = annotation;

    return annotationView;
}
4

1 回答 1

1

要获得带有自定义图像的标注,在viewForAnnotation委托方法中,您可以将leftCalloutAccessoryView或设置rightCalloutAccessoryView为您的图像(尽管右侧的通常用于显示按钮):

annotationView.canShowCallout = YES;
UIImage *img = [UIImage imageNamed:@"something.png"];
annotationView.leftCalloutAccessoryView = 
    [[[UIImageView alloc] initWithImage:img] autorelease];
于 2011-07-24T20:14:18.577 回答