自定义注释引脚

时间:2012-06-12 16:43:32

标签: ios mkmapview mkannotationview

我有课

@interface MyLocation : NSObject <MKAnnotation> 

@property (copy) NSString *name;
@property (copy) NSString *address;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, strong) UIImage *banner;
@property (nonatomic, strong) NSString *descr;

当我在地图上添加位置时,我希望该方法- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation显示横幅....我该怎么做?

    - (MKAnnotationView*) mapView:
(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
    {
    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[MyLocation class]]) {
        MKPinAnnotationView *annotationView = (MKPinAnnotationView*)
        [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] 
    initWithAnnotation:annotation reuseIdentifier:identifier];
                        } else {
                            annotationView.annotation = annotation;
                                }
                annotationView.enabled = YES;
                annotationView.canShowCallout = YES;
                annotationView.image = [UIImage imageNamed:@"Image2.jpg"];

                return annotationView;
        }
        return nil;
    }

此方法更改所有注释引脚,但我需要为每个注释添加不同的图像。 谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

您必须将MKAnnotationView用于自定义引脚,因为MKPinAnnotationView始终显示“默认”引脚。

答案 1 :(得分:0)

自定义CLASS MKAnnotationView,U可以更改引脚 请参阅apple中的示例代码:map callouts

相关问题