MKAnnotation的自定义标注视图?

时间:2011-08-04 16:25:47

标签: iphone objective-c ios mkannotation mkannotationview

标准标注,黑色泡泡,很好,但这可以定制吗?例如,我想制作一个白色泡泡版。

1 个答案:

答案 0 :(得分:7)

这里有一个很好的答案:Customizing the MKAnnotation Callout bubble

这个答案由@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;
}