【问题标题】:How to create custom annotation and callout in iphone如何在 iphone 中创建自定义注释和标注
【发布时间】:2012-05-24 14:31:28
【问题描述】:

我想在 MKMapView 上创建自定义注释和标注。我必须创建尺寸更大的注释,并且必须显示三四行文本(标签)。那么如何创建自定义注释和标注气泡。

提前致谢。

阿什

【问题讨论】:

标签: xcode mkmapview mkannotation mkannotationview


【解决方案1】:

您应该只重新实现 3 个方法:

自定义您的注释使用:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation

这里只添加你需要的子视图

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

这里只是从 superView 中删除您的自定义 callOutView

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view

查看blog了解详情

【讨论】:

    【解决方案2】:

    你可以用这个。

    - (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
        MKAnnotationView *a = [ [ MKAnnotationView alloc ] initWithAnnotation:newAnnotation reuseIdentifier:@"PinView"];
    
        if ( a == nil )
            a = [ [ MKAnnotationView alloc ] initWithAnnotation:newAnnotation reuseIdentifier: @"PinView" ];
    
        a.image = [ UIImage imageNamed:@"Image.png" ];
        a.canShowCallout = YES;
        a.rightCalloutAccessoryView = [ UIButton buttonWithType:UIButtonTypeDetailDisclosure ];
        UIImageView *imgView = [ [ UIImageView alloc ] initWithImage:[ UIImage imageNamed:@"Image.png" ] ];
        a.leftCalloutAccessoryView = imgView;
    
        return a;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 2017-05-05
      相关资源
      最近更新 更多