这是iOS 11.x Swift 4中的样子,请注意,如果你犯了与我相同的错误,这将不起作用
MKPin注释视图
。这将制作一个别针,您将无法更改它后面的图像。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let reuseId = "pin"
var pav:MKAnnotationView?
if (pav == nil)
{
pav = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pav?.isDraggable = true
pav?.canShowCallout = true
pav?.image = UIImage(named: "WIP.png")
pav?.calloutOffset = CGPoint(x: -8, y: 0)
pav?.autoresizesSubviews = true
// pav?.rightCalloutAccessoryView = UIButton(type: .roundedRect)
pav?.leftCalloutAccessoryView = UIButton(type: .contactAdd)
}
else
{
pav?.annotation = annotation;
}
return pav;
}