小编use*_*631的帖子

iOS:为什么我不能让mapkit显示自定义注释图像?

认为使用我自己的自定义图钉进行注释会非常容易.

但我从来没有能够让它工作,我不明白为什么!

我只是使用:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    NSString *annotationIdentifier = @"CustomViewAnnotation";
    CustomAnnotationView * customAnnotationView = (CustomAnnotationView *) [self.mapview dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    if(!customAnnotationView)
    {
        customAnnotationView=[[CustomAnnotationView alloc] initWithAnnotationWithImage:annotation
                                                                       reuseIdentifier:annotationIdentifier 
                                                                   annotationViewImage:[UIImage imageNamed:@"map_location_pin.png"]];
    }

    customAnnotationView.image=[UIImage imageNamed:@"map_location_pin.png"];

    customAnnotationView.canShowCallout= YES;

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

我认为这应该有效,因为UIImage是它想要的东西,而且我的项目中确实有.png文件.

它从不使用我的图像,只是标准的红色图钉.我在这做错了什么?

annotations mapkit mkmapview ios

2
推荐指数
1
解决办法
4299
查看次数

标签 统计

annotations ×1

ios ×1

mapkit ×1

mkmapview ×1