ios - leftCalloutAccessoryView 已设置但现在正在显示

标签 ios swift mkmapview

我正在设置点击 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
}

这里有一个缺失箭头图像的示例。

What we see when I click on the pin


这里我们有您期望看到的东西,一个灰色箭头。

Image name, the image you would expect to see

最佳答案

好的,我找到了问题。

问题是系统默认为图像添加了色调,因此我需要覆盖色调以获得正确的颜色。

新代码如下所示。

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/

相关文章:

ios - 弹出式 UIViewController

objective-c - iOS 5 错误 : UIWebView and goBack and goForward

iphone - ios中的可点击链接?

iphone - 单击 MKAnnotationView 中的按钮

ios - 在 IOS 8 中的 MKMapView 上添加按钮

ios - 在 heightForRowAtIndexPath 中推断行高

Objective-C 枚举在 Swift 中不可见

swift - 导入的框架找不到应该在其中的框架

ios - 是否可以在 UIScrollView 中添加 UITableView?

iphone - 从来自网络服务的位置创建多个 MKOverlays 折线