U.A.Malik
U.A.Malik

Reputation: 78

How to show a UIView just above the MKpointAnnotation Pin

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?

Upvotes: 0

Views: 1265

Answers (2)

Mr. Xcoder
Mr. Xcoder

Reputation: 4795

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!!!

Upvotes: 0

Subin K Kuriakose
Subin K Kuriakose

Reputation: 849

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

Upvotes: 1

Related Questions