【问题标题】:custom annotation pin自定义注释引脚
【发布时间】:2012-06-12 16:43:31
【问题描述】:

我有课

@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&lt;MKAnnotation&gt;)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;
    }

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

【问题讨论】:

    标签: ios mkmapview mkannotationview


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      自定义 CLASS MKAnnotationView,U 可以更改引脚 查看来自苹果的示例代码:map callouts

      【讨论】:

      • 请注意 link-only answers 是不鼓励的,所以答案应该是寻找解决方案的终点(与另一个中途停留的参考相比,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
      猜你喜欢
      • 2013-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      相关资源
      最近更新 更多