美文网首页
2019-08-21扩大UIButton 点击范围

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

作者: 多肉散散步 | 来源:发表于2019-08-21 15:41 被阅读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)
        }
    }
    

    相关文章

      网友评论

          本文标题:2019-08-21扩大UIButton 点击范围

          本文链接:https://www.haomeiwen.com/subject/icqisctx.html