Как изменить цвет булавки в Swift 4.0 в просмотре карты - PullRequest
0 голосов
/ 28 июня 2018

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
}

Чего мне не хватает?

1 Ответ

0 голосов
/ 28 июня 2018

Предполагая, что ваш ViewController соответствует MKMapViewDelegate протоколу, замените следующую строку кода:

    view?.tintColor = .blue

с этим

    view?.pinTintColor = .blue

pinTintColor необходимо установить для добавления цвета. Подробнее о pinTintColor можно прочитать здесь

Надеюсь, это поможет!

...