自定义 UIButtonType

Customising UIButtonType

我有一个 MKPinAnnotationView,它有一个 leftCalloutAccessoryView,它接收一个 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

我正在尝试自定义 UIButtonType 以显示我的图标,但我无法确定如何操作。

谢谢。

像这样:

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