扩大UIButton点触区域

1:新建类继承UIButton

2:在.m文件粘贴以下代码

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event

{

CGRect bounds = self.bounds;

//若原热区小于44x44,则放大热区,否则保持原大小不变

CGFloat widthDelta = MAX(44.0 - bounds.size.width, 0);

CGFloat heightDelta = MAX(44.0 - bounds.size.height, 0);

bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);

return CGRectContainsPoint(bounds, point);

}

3:收工。

你可能感兴趣的:(扩大UIButton点触区域)