Custom Swift Image MKPointAnnotation

I am trying to create a custom "badget" for my MKPointAnnotation in swift but it fails because MKPointAnnotation has no property like 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)

      

Has anyone come up with a quick solution for this?

+3


source to share


1 answer


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

}

      



+10


source







All Articles