Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom callout view for MKAnnotation?

The standard callout, a black bubble, is nice, but can this be customized? For instance I would like to make a white bubble version.

like image 225
cannyboy Avatar asked Aug 04 '11 16:08

cannyboy


1 Answers

There is a great answer to this problem here: Customizing the MKAnnotation Callout bubble

Where this answer is given by @MathieuF:

- (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 pin;
}
like image 64
rich Avatar answered Oct 15 '22 15:10

rich