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)
}
}
网友评论