iOS 11.x Swift 4.0
私が解決できる限り、これは機能するはずですが、機能しません。コンパイルされますが、ピンの色は変わりませんか?
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
var view: MKAnnotationView! = mapView.dequeueReusableAnnotationView(withIdentifier: Constants.AnnotationViewReuseIdentifier) as? MKPinAnnotationView
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: Constants.AnnotationViewReuseIdentifier)
view.canShowCallout = true
view?.tintColor = .blue
} else {
view.annotation = annotation
}
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
view.leftCalloutAccessoryView = UIButton(frame: Constants.LeftCalloutFrame)
view.isDraggable = true
return view
}
私は何が欠けていますか?
あなたのViewController に準拠MKMapViewDelegate プロトコル、以下のコード行を置き換えます:
これとともに
pinTintColor 色を追加するために設定する必要があります。詳しく読むことができますpinTintColor ここに
お役に立てれば!