简体   繁体   English

使用Apple新的注释图钉徽标更改注释图钉的颜色

[英]Changing colour of annotation pin with Apple's new annotation pin logo

I'm trying to change the colour of my annotation pins. 我正在尝试更改注释图钉的颜色。 However, I am wanting it to change the colour of the new Apple annotation logo. 但是,我希望它更改新的Apple批注徽标的颜色。 Instead, when the colours change, the new logo (as shown below) converts to the old logo (as shown below). 相反,当颜色改变时,新徽标(如下所示)将转换为旧徽标(如下所示)。

Is there anyway to change the colour as well as keep the new annotation pin? 是否有更改颜色以及保留新注释脚的方法?

Here's my code: 这是我的代码:

class MyPointAnnotation : MKPointAnnotation {
    var pinTintColor: UIColor?
}

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "myAnnotation") as? MKPinAnnotationView

    if annotationView == nil {
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
        annotationView?.canShowCallout = true
       } else {
        annotationView?.annotation = annotation
    }
    if annotation is MKUserLocation {
        return nil
    }
    if let annotation = annotation as? MyPointAnnotation {
        annotationView?.pinTintColor = annotation.pinTintColor
    }
            return annotationView
}

self.map.delegate = self
/// in view did load

Old pin: 旧图钉:

老针

New pin: 新图钉:

新别针

any input would be greatly appreciated! 任何投入将不胜感激!

Use MKMarkerAnnotationView instead of MKPinAnnotationView. 使用MKMarkerAnnotationView代替MKPinAnnotationView。

if annotationView == nil {
    annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
    annotationView?.canShowCallout = true
   } else {
    annotationView?.annotation = annotation
}

MKMarkerAnnotationView uses markerTintColor rather than pinTintColor. MKMarkerAnnotationView使用markerTintColor而不是pinTintColor。 However, this only works on iOS 11. The new icon is only present in iOS 11. 但是,这仅在iOS 11上有效。新图标仅在iOS 11中存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM