0

I've a MKPinAnnotationView which has a leftCalloutAccessoryView that receives a UIButton.

let pinView = MKPinAnnotationView()

pinView.pinTintColor = UIColor.blueColor()
pinView.canShowCallout = true
pinView.draggable = true

let button: UIButton = UIButton(type: UIButtonType.DetailDisclosure)
button.addTarget(self, action: "navigateUserFromCoordinates:", forControlEvents: UIControlEvents.TouchUpInside)

pinView.leftCalloutAccessoryView = button

return pinView

I'm trying to customise the UIButtonType to display an icon of mine but I couldn't determine how to do so.

Thanks.

Can
  • 4,516
  • 6
  • 28
  • 50

1 Answers1

1

Like so:

let pinView = MKPinAnnotationView()
pinView.pinTintColor = .blueColor()
pinView.canShowCallout = true
pinView.draggable = true

let button = UIButton(type: .Custom)
button.setImage(UIImage(named: "yourImage"), forState: .Normal)
button.sizeToFit()
button.addTarget(self, action: "navigateUserFromCoordinates:", forControlEvents: .TouchUpInside)
pinView.leftCalloutAccessoryView = button

return pinView
fluidsonic
  • 4,655
  • 2
  • 24
  • 34