gpt4 book ai didi

swift - 使用 Apple 的新注释图钉 Logo 更改注释图钉的颜色

转载 作者:行者123 更新时间:2023-11-28 14:57:59 25 4
gpt4 key购买 nike

我正在尝试更改注释图钉的颜色。但是,我希望它能改变新的 Apple 注释标志的颜色。相反,当颜色发生变化时,新 Logo (如下所示)将转换为旧 Logo (如下所示)。

有没有办法改变颜色并保留新的注释图钉?

这是我的代码:

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

任何输入将不胜感激!

最佳答案

使用MKMarkerAnnotationView而不是 MKPinAnnotationView。

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

MKMarkerAnnotationView 使用 markerTintColor而不是 pinTintColor。但是,这仅适用于 iOS 11。新图标仅出现在 iOS 11 中。

关于swift - 使用 Apple 的新注释图钉 Logo 更改注释图钉的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49163910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com