2
votes

I have added this:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation {
        return nil
    }

    let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "id")

    if let title = annotation.title{
        if title! == "P"{
            pinView.pinTintColor = UIColor.yellow
        }
        else{
            pinView.pinTintColor = UIColor.gray
        }
    }
    return pinView
}

But when I do this I can´t see my titles when I click on an annotation anymore, any ideas why?

1

1 Answers

4
votes

You need to add the canShowCallout on your pinView. If the value of the canShowCallout property is true, a standard callout bubble is shown when the user taps a selected annotation view. The callout uses the title and subtitle text from the associated annotation object.

So just add the following row to your viewFor function and you´ll see the title.

pinView.canShowCallout = true