在ios中的Mkmapview中的自定义标注

时间:2013-04-05 10:30:42

标签: iphone ios ios5 mkmapview

我必须在ios上显示注释的自定义视图,我必须在自定义视图中显示7个图像,名称和详细信息公开按钮。点击详细信息披露按钮,我必须调用新的视图控制器。我该怎么办?

1 个答案:

答案 0 :(得分:0)

  -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    // Define your reuse identifier.
    MKPinAnnotationView *annotationView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

    annotationView.pinColor = MKPinAnnotationColorGreen;
    annotationView.enabled = YES;
    annotationView.canShowCallout = YES;

    // Adding Button on annotation callout  which is your detail disclosure button//
    UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0.0f,0.0f,28.0f,22.0f)];
    [rightButton setImage:[UIImage imageNamed:@"rightArrow.png"] forState:UIControlStateNormal];
    [rightButton addTarget:self
                   action:@selector(pressDetailBtn:)
         forControlEvents:UIControlEventTouchUpInside];

    annotationView.rightCalloutAccessoryView = rightButton;
    annotationView.image=[UIImage imageNamed:@"orangePin.png"];
    annotationView.opaque = NO;

    return annotationView;
}
-(void)pressDetailBtn:(id)sender
{

      YourVC code here
}