2019-08-21扩大UIButton 点击范围

2019-08-21  本文已影响0人  多肉散散步
class ExpandButton: UIButton {
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        let margin: CGFloat = 5 //可根据情况修改
//self.bounds = (0,0,12,12)
        let area = self.bounds.insetBy(dx: -margin, dy: -margin)
//area:CGRect (X:X +dx,Y:Y +dy,Width:Width -2*dx,Height:Height -2*dy)
//area = (0-5,0-5,12+2*5,12+2*5)
        return area.contains(point)
    }
}
上一篇下一篇

猜你喜欢

热点阅读