2

I am trying to set names under pins that are on a map. Each name should be specific. I am not using default pins, hence each pin is a specific image. I was thinking of generating some kind of image that would present the image of the pin and the name as a label under it. Then append the whole thing as the image of the mkannotationview. But this looks like a mess to me.

Is there a way I could possibly append a label under a mkannotationview? Or should a make a custom mkannotationview?

Thank you for your time.

Quentin Malgaud
  • 405
  • 6
  • 21
  • See http://stackoverflow.com/questions/9822756/replace-icon-pin-by-text-label-in-annotation for an example in Objective-C. You could also wrap the code in a custom MKAnnotationView subclass. –  Mar 28 '15 at 20:07

2 Answers2

2

Starting with iOS 11, if you subclass MKMarkerAnnotationView, you get those texts below the bubble for free, including collition detections: the text is sometimes rendered more left or right, depending where there is some space left on the map.

Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
1

The MKAnnotationView class is a subclass of UIView, so you should be able to subclass it fairly easily.

I would probably create a custom subclass, and have my subclass add a label as a subview of the MKAnnotationView. You might need to adjust the frame of the view to make room for the label you're adding.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • That did the job perfectly. Thank you Duncan. Thank you Anna as well. I could indeed get useful infos from the post you mentioned even thought I don't know objective-C – Quentin Malgaud Mar 29 '15 at 00:17