【问题标题】:Custom callout view for MKAnnotation?MKAnnotation 的自定义标注视图?
【发布时间】:2011-08-04 16:25:47
【问题描述】:

标准标注,黑色气泡,很好,但是可以自定义吗?比如我想做一个白色泡泡版。

【问题讨论】:

标签: iphone objective-c ios mkannotation mkannotationview


【解决方案1】:

这里有一个很好的答案: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;
}

【讨论】:

  • 这很好,但它不处理从气泡中下来的三角形,或可变宽度的气泡(包含可变数量的文本)
  • @cannyboy 这里有同样的问题。你能告诉我你是怎么解决的吗??
  • 我需要两个按钮,一个在 leftView 和 rightView 上?如何在左视图和右视图中添加自定义按钮?
猜你喜欢
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 2011-11-19
  • 1970-01-01
相关资源
最近更新 更多