27
2017
09

iOS-增大按钮点击范围

重写该方法:

-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    //当前btn大小
    CGRect btnBounds = self.bounds;
    //扩大点击区域,想缩小就将-10设为正值
    btnBounds = CGRectInset(btnBounds, -10, -10);

    //若点击的点在新的bounds里,就返回YES
    return CGRectContainsPoint(btnBounds, point);
}

例子:

UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
[self.view addSubview:view1];

CGRect rect2 = CGRectInset(view1.frame, 10, 20);
UIView *view2 = [[UIView alloc]initWithFrame:rect2];
[self.view addSubview:view2];
NSLog(@"%@",NSStringFromCGRect(rect2));



尊重原创:
iOS修改button的点击范围

上一篇:Android studio 常用快捷键 下一篇:LimeSDR + Osmo-TRX + OpenBTS搭建简易GSM基站测试