2017-12-03 6 views
0

私はdidSelect view: MKAnnotationViewで、ピンの色を変更しようとしています:スウィフト:didSelectビューの変更ピンの色: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 
} 

をしかし、私はピンをタップしたときに、それが変化していないが - 赤のまま。なぜ誰かがそれを変更する方法を知っていますか?

答えて

1

使用pinTintColor代わりに私がMKAnnotationViewとtintColorに変更したが、それは、それが大きくなる助けにはならないが、赤のままtintColor

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

デリゲート関数は次のとおりです。

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

の –

+1

@ElenaRubilovaあなたをあなたのMKAnnotationViewをMKPinAnnotationViewにキャストする必要があります、あなたはKosukeの答えに従うことができます;) –

関連する問題