自定义UIButtonType

时间:2015-11-27 12:58:54

标签: ios swift mapkit mapkitannotation

我的malloc() 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 以显示我的图标但我无法确定如何执行此操作。

感谢。

1 个答案:

答案 0 :(得分: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