0

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?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
U.A.Malik
  • 78
  • 8

2 Answers2

1

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

Community
  • 1
  • 1
0

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

Community
  • 1
  • 1
Mr. Xcoder
  • 4,719
  • 5
  • 26
  • 44