如何在iPhone中创建自定义注释和标注

时间:2012-05-24 14:31:29

标签: xcode mkmapview mkannotation mkannotationview

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

提前致谢。

与Ashish

2 个答案:

答案 0 :(得分: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了解详情

答案 1 :(得分:-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;
}