扩大按钮UIButton的点击范围

作者: 夜千寻墨 | 来源:发表于2015-11-29 00:26 被阅读3376次

首先,我们得继承一个UIButton,然后重写 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 这个方法,苹果的概念是点击区域最好不小于44 point,所以我们根据这个数值计算我们的点击区域。上代码。

自定义按钮 扩大按钮点击范围

```

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

{

CGRectbounds =self.bounds;

CGFloatwidthDelta =44.0- bounds.size.width;

CGFloatheightDelta =44.0- bounds.size.height;

bounds =CGRectInset(bounds, -0.5* widthDelta, -0.5* heightDelta);//注意这里是负数,扩大了之前的bounds的范围

returnCGRectContainsPoint(bounds, point);

}

```

相关文章

网友评论

本文标题:扩大按钮UIButton的点击范围

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