Swift: 在 didSelect 视图中更改图钉颜色:MKAnnotationView

Swift: change pin color in didSelect view: MKAnnotationView

我正在尝试更改 didSelect view: MKAnnotationView 中的图钉颜色:

func mapView(_ mapView: MKMapView,
             didSelect view: MKAnnotationView) {
    let selectedAnnotation = view.annotation as? MKPointAnnotation //ColorPointAnnotation
    //self.textField.text = selectedAnnotation!.title
    preferredSpot = selectedAnnotation!.title!
    view.tintColor = UIColor.green
}

但是当我点击图钉时它没有改变 - 仍然是红色。有人知道为什么 and/or 怎么改吗?

委托函数为:

optional func mapView(_ mapView: MKMapView, 
        didSelect view: MKAnnotationView)

使用pinTintColor代替tintColor

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if let view = view as? MKPinAnnotationView {
        view.pinTintColor = UIColor.green
    }
}

由于 pin tint 现已弃用,我想我会根据 Kosuke 对 markerTint 的回答分享我的更新版本。

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if let view = view as? MKMarkerAnnotationView {
        view.markerTintColor = UIColor.systemBlue
    }
}