How to show a UIView just above the MKpointAnnotation Pin

1.2k views Asked by At

I want to show a UIView just above the pin location and if the user moves around the map the UIView should remain above the pin location. I dont want to use the callout bubble. Is there any other way?

2

There are 2 answers

0
Subin K Kuriakose On

in iOS 9 we have a new property named detailCalloutAccessoryView

You can create a view and set as

annotationView.detailCalloutAccessoryView = tempView 

Please check the link to get more details

MapKit iOS 9 detailCalloutAccessoryView usage

1
Mr. Xcoder On

Try using this code:

func mapView(_ mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView {
    if (annotation is MKUserLocation) {
        return nil
    }
    else if (annotation is YourAnnotationClassHere) {
        let identifier = "MyCustomAnnotation"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
        if annotationView {
            annotationView.annotation = annotation
        }
        else {
            annotationView = MKAnnotationView(annotation, reuseIdentifier: identifier)
        }
        annotationView.canShowCallout = false
        // set to YES if using customized rendition of standard callout; set to NO if creating your own callout from scratch
        annotationView.image = UIImage(named: "your-image-here.png")!
        return annotationView
    }

    return nil
}

That's mainly what you need for that to work. This is a swift version of this answer right here: How to create Custom MKAnnotationView and custom annotation title and subtitle

Hope it helped!!!