标准标注(黑色气泡)很好,但是可以自定义吗?例如,我想制作一个白色气泡的版本。

最佳答案

这里有一个很好的解决此问题的方法: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;
}

关于iphone - 为MKA注释自定义标注 View ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6945045/

10-12 01:24