我正在设置点击 map 图钉时要显示的附加信息。
在此注释中,我将带有图像的按钮传递到 rightCalloutAccessoryView,但它似乎保留了空间,但并未显示图像。
我还应该注意,这是一个应用程序的副本,它确实有效,并且图像已被替换为不同的配色方案,但我认为该图像的大小没有改变,但如果附件 View 对图像大小那么这可能是一个问题。
希望这只是我缺少的 RightCalloutAccessoryView 的细微差别。
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let reuseId = "mapViewPin"
var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
anView!.annotation = annotation
let button : UIButton = UIButton(type: UIButtonType.DetailDisclosure)
button.setImage(UIImage(named: "goArrow"), forState:UIControlState.Normal)
button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
anView!.rightCalloutAccessoryView = button
return anView
}
这里有一个缺失箭头图像的示例。
这里我们有您期望看到的东西,一个灰色箭头。
最佳答案
好的,我找到了问题。
问题是系统默认为图像添加了色调,因此我需要覆盖色调以获得正确的颜色。
新代码如下所示。
let button : UIButton = UIButton(type: UIButtonType.DetailDisclosure)
button.setImage(UIImage(named: "goArrow")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), forState:UIControlState.Normal)
button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
anView!.rightCalloutAccessoryView = button
return anView
这里的关键是使用“imageWithRenderingMode”并将其设置为“AlwaysOriginal”,这会删除默认色调,该色调使该图像完全变白。
关于ios - leftCalloutAccessoryView 已设置但现在正在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33504595/