我尝试使用BarButton,但这是错误的:
CGSize thumbSize = CGSizeMake(30.0, 30.0);
UIImageView *annotationThumbnail = [[UIImageView alloc] initWithImage:[((Sight *)annotation).thumbnail imageToFitSize:thumbSize method:MGImageResizeScale]];
UIBarButtonItem *annotationButton = [[UIBarButtonItem alloc] initWithCustomView:annotationThumbnail];
annotationView.leftCalloutAccessoryView = annotationButton;
答案 0 :(得分:2)
UIBarButtonItem
不是UIView的子类,因此在需要视图的地方使用UIBarButtonItem
的实例是行不通的。相反,您可以像这样使用annotationThumbnail
:
annotationView.leftCalloutAccessoryView = annotationThumbnail;
如果您改为使用UIControl子类,例如UIButton,如果有人点击了标注附件,地图的委托将收到-mapView:annotationView:calloutAccessoryControlTapped:
消息:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:someImage forState:UIControlStateNormal];
button.frame = someRect;
annotationView.leftCalloutAccessoryView = button;