Customizing the MKAnnotation Callout bubble

sbmandav picture sbmandav · Nov 4, 2010 · Viewed 22.3k times · Source

I have a requirement in my application map page. I have to customize the Callout bubbles. I need to add an image, two labels and a button with specific height and width of each.

I have gone through web and could not find a proper link that explains how to customize the callout bubbles. If any one of you come across or know about it please share with me.

any simple examples or links would be really great.

Thanks in advance suresh

Answer

MathieuF picture MathieuF · Nov 4, 2010

An example to help you :

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{   
    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"loc"];

    // Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    button.frame = CGRectMake(0, 0, 23, 23);
    annotationView.rightCalloutAccessoryView = button;

    // Image and two labels
    UIView *leftCAV = [[UIView alloc] initWithFrame:CGRectMake(0,0,23,23)];
    [leftCAV addSubview : yourImageView];
    [leftCAV addSubview : yourFirstLabel];
    [leftCAV addSubview : yourSecondLabel];
    annotationView.leftCalloutAccessoryView = leftCAV;

    annotationView.canShowCallout = YES;

    return annotationView;
}

For more informations, look at this : http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html%23//apple_ref/occ/cl/MKAnnotationView