0

我有课

@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;
    }

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

4

2 回答 2

0

自定义 CLASS MKAnnotationView,和 U 可以更改引脚参见苹果的示例代码:地图标注

于 2013-10-22T11:29:29.290 回答
0

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

于 2012-06-26T11:09:48.340 回答