因為Apple 規(guī)定 點擊范圍最好不要小于 44.0 point?
首先瑞你,我們得繼承(或者擴展類)一個UIButton,然后重寫 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 這個方法?
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
//這種是 自己定義button的具體范圍
CGRect bounds =self.bounds;
CGFloat widthDelta =44.0- bounds.size.width;
CGFloat heightDelta =44.0- bounds.size.height;
/*? 1.注意這里是負數(shù),擴大了之前的bounds的范圍
*? 2.通過第二個參數(shù) dx和第三個參數(shù) dy 重置第一個參數(shù)rect 作為結(jié)果返回。
*? 重置的方式為壹甥,首先將rect 的坐標(origin)按照(dx,dy) 進行平移,然后將rect的大泻(size) 寬度縮小2倍的dx句柠,高度縮小2倍的dy;
?* ??所以我們這里設(shè)置的范圍就是44.0 *44.0 如果想設(shè)置大點就把上面的寬高44.0? 改一下
*/
bounds =CGRectInset(bounds, -0.5* widthDelta, -0.5* heightDelta);
//CGRectContainsPoint函數(shù):判斷給定的點是否被一個CGRect包含
return CGRectContainsPoint(bounds, point);
}
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
//這種是范圍向外擴展 2*10? 如果是正的 就是縮小 2*10
CGRect bounds =self.bounds;
bounds =CGRectInset(bounds,-10 ,-10 );
return CGRectContainsPoint(bounds, point);
}