Swift扩大button的点击范围

给UIbutton写一个继承,重写point方法

class ZQButton:UIButton{
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        let zqmargin:CGFloat = -10
        let clickArea = bounds.insetBy(dx: zqmargin, dy: zqmargin)
        return clickArea.contains(point)
    }
}

参考:

https://www.jianshu.com/p/a0bb0a71055d

你可能感兴趣的:(Swift扩大button的点击范围)