How to make the frame of a button custom shape in Swift 2
问题 I want the button to be reactive to tap only in the custom polygonal shape that I create and not in the CGRect frame. button.frame only supports CGRect. 回答1: Here is an example of a button that only responds to touches within a certain area. class MyButton: UIButton { var path: UIBezierPath! override func awakeFromNib() { backgroundColor = UIColor.greenColor() addTarget(self, action: #selector(touchDown), forControlEvents: .TouchDown) } override func drawRect(rect: CGRect) { path =