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.

4

1 回答 1

1

像这样:

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
于 2015-11-27T13:07:24.247 回答