定制别针

func mapView(mapView:MKMapView,viewForAnnotation注解:MKAnnotation)-> MKAnnotationView? {

我正在使用MKMapViewDelegate的方法来自定义引脚。

后卫!annotation.isKindOfClass(MKUserLocation)排除了用户位置,因此我仍然拥有当前位置的标准蓝点。

我们需要创建一个销钉实例,稍后将其应用于地图上的位置。 让我们从分配标识符开始:

让注解标识符=“ AnnotationIdentifier”

然后在其上调用dequeuedAnnotationView

然后,我们需要配置将分配给该引脚的图像:

commentView.canShowCallout = true以显示图像。 然后,您可以将UIImage分配给notesView.image

但是,每次地图加载时,我需要将多个图像随机分配给引脚。 为了实现它,我创建了一个图像数组,并借助arc4random_uniform方法从该数组中以随机索引分配了一个图像:

如果让注解=注解{

//在此处配置注释视图

subscriptionView.canShowCallout = true

让unicorn = UIImage(名称:“ unicorn.png”)

让熊猫= UIImage(名称:“ redpanda3d.png”)

让arr = [独角兽,熊猫]

让randomIndex = Int(arc4random_uniform(UInt32(arr.count)))

commentView.image = arr [randomIndex]

}