5

I have a view to a calloutDetail: annotationView.detailCalloutAccessoryView = mapInformationView.view

It is working just fine, but I don't want to display a title/subtitle, just my custom view. But when I left title/subtitle empty the callout isn't displayed.

So, How can I hide them or just change their font size and name?

1 Answers1

0

One way to hide the title (or subtitle) label is to set the MKAnnotation's title (or subtitle) property to nil.

If you want the title to show on the marker, but not on the callout, toggle the title value in a subclass of MKAnnotationView overriding setSelected(_:animated:).

override func setSelected(_ selected: Bool, animated: Bool) {
    if selected {
        annotation.title = nil
    } else {
        annotation.title = "Title"
    }
    
    super.setSelected(selected, animated: animated)
}
Avario
  • 4,655
  • 3
  • 26
  • 19
  • This doesn't appear to work - the compiler complains that `annotation.title` is a get-only property. – Alnitak Dec 01 '22 at 14:26
  • setting the annotation's title empty in `mapView(_ mapView: MKMapView, didSelect view: MKAnnotation) ` mostly works, but produces an annoying animation to get rid of the blank space left behind. – Alnitak Dec 01 '22 at 14:46