Swift MKPointAnnotation自定义图片

我尝试在swift中为我的MKPointAnnotation创build一个自定义的“badget”,但是因为MKPointAnnotation没有任何像image

var information = MKPointAnnotation() information.coordinate = location information.title = "Test Title!" information.subtitle = "Subtitle" information.image = UIImage(named: "dot.png") //this is the line whats wrong Map.addAnnotation(information) 

有人想出了一个像这样的解决scheme?

 func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if !(annotation is MKPointAnnotation) { return nil } var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("demo") if annotationView == nil { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "demo") annotationView!.canShowCallout = true } else { annotationView!.annotation = annotation } annotationView!.image = UIImage(named: "image") return annotationView }