Fast custom callout for MKMapView

I use a custom callout view for mapview. I get this conclusion

enter image description here

In annotation I use

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

     let reuseId = "mapPin"
   var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? CustomCalloutView
    if anView == nil {
    anView=CustomCalloutView(annotation: annotation,reuseIdentifier:reuseId)
        anView!.image = UIImage(named:"mappin.png")
        let button : UIButton = UIButton.buttonWithType(UIButtonType.DetailDisclosure) as! UIButton
        button.addTarget(self, action: "buttonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
        anView!.rightCalloutAccessoryView=button
     //anView!.addSubview(viewC)
    mapViewControl.addAnnotation(annotation)
    }
    else {
        anView!.annotation = annotation
    }

    return anView
}

and call popup

    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!){
    var viewC:UIView=UIView(frame: CGRectMake(0, 0, 50, 50))
    viewC.backgroundColor = UIColor.blackColor()

   view.addSubview(viewC)
    viewC.center = CGPointMake(viewC.bounds.size.width*0.1, -viewC.bounds.size.height*0.5)


}
+4
source share
1 answer

I got a solution. This is a very small change. In viewForNnotation, hide the main leader, as shown below,

anView!.canShowCallout = false
+1
source

All Articles