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.
我试着在地图上的大头针下面设置名字。每个名字都应该是特定的。我没有使用默认的大头针,因此每个大头针都是一个特定的图像。我想生成某种图像来显示大头针的图像以及它下面的标签。然后将整个内容追加为mkannotationview的映像。但在我看来这是一团糟。
Is there a way I could possibly append a label under a mkannotationview? Or should a make a custom mkannotationview?
是否有一种方法可以在mkannotationview下附加一个标签?或者一个定制的mkannotationview?
Thank you for your time.
谢谢您的时间。
2 个解决方案
#1
1
The MKAnnotationView class is a subclass of UIView, so you should be able to subclass it fairly easily.
MKAnnotationView类是UIView的一个子类,所以你应该能够很容易地子类化它。
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.
我可能会创建一个自定义子类,并让子类添加一个标签作为MKAnnotationView的子视图。您可能需要调整视图的框架来为添加的标签腾出空间。
#2
1
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.
从ios11开始,如果你子类化MKMarkerAnnotationView,你可以在气泡下面免费获得这些文本,包括碰撞检测:文本有时被渲染得更向左或向右,这取决于地图上还剩下的空间。
#1
1
The MKAnnotationView class is a subclass of UIView, so you should be able to subclass it fairly easily.
MKAnnotationView类是UIView的一个子类,所以你应该能够很容易地子类化它。
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.
我可能会创建一个自定义子类,并让子类添加一个标签作为MKAnnotationView的子视图。您可能需要调整视图的框架来为添加的标签腾出空间。
#2
1
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.
从ios11开始,如果你子类化MKMarkerAnnotationView,你可以在气泡下面免费获得这些文本,包括碰撞检测:文本有时被渲染得更向左或向右,这取决于地图上还剩下的空间。