MapKit and Core Location · Challenge: Customize the Annotation | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/9236-mapkit-and-core-location/lessons/15

Nice course! How can we auto scale the detailCalloutAccessoryView and the image it contains?

After doing the challenge to add the detailCalloutAccessoryView, some of the images did not fit and were scaled to have a different aspect ratio.

I set the contentMode of the imageView as below and this scaled the image nicely, but the annotationView still was too big and needs to be scaled to match the imageView.

  imageView.contentMode = .scaleAspectFit
  annotationView?.detailCalloutAccessoryView = imageView

I haven’t tried but I believe you can call core graphics calls with your view and thus do the scaling yourself. Granted, it takes a little bit of code but we have a complete course on it, if you are interested.