我已经创建了一个MKMapView,但我需要在Swift 2中添加多个带有图像的注释,我该怎么做?
首先你必须创建一个MKAnnotationView,使用这个函数来创建你的标记:
internal func setupMarker(image:UIImage,long:Double,lat:Double,title:String,subtitle:String) -> MKAnnotationView{
var pinAnnotationView:MKAnnotationView!
var pointAnnotation:MKPointAnnotation!
pointAnnotation = MKPointAnnotation()
pointAnnotation.title = title
pointAnnotation.subtitle = subtitle
pointAnnotation.coordinate = CLLocationCoordinate2D(latitude:lat, longitude:long)
pinAnnotationView = MKPinAnnotationView(annotation: pointAnnotation, reuseIdentifier: nil)
pinAnnotationView.image = image
pinAnnotationView.canShowCallout = true
return pinAnnotationView
}
创建您的标记:
var marker = setupMarker(store.image.image, long: store.location.longitude, lat: store.location.latitude, param: "store",storeId: store.description))
将标记添加到MapView
mapView.addAnnotation(marker.annotation!)