自定义按钮类型CustomButton,继承UIButton,重写pointInside函数改变点击响应范围。

 

例如,按钮点击范围比实际高度上下增加6。

UIButton设置按钮点击范围大于可视范围

CustomButton.h

@interface CustomButton : UIButton
@end

 

CustomButton.m

#import "CustomButton.h"
CGFloat const ButtonInset = 6.f;
@implementation CustomButton
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
    CGRect newArea = CGRectMake(self.bounds.origin.x, self.bounds.origin.y - ButtonInset, self.bounds.size.width, self.bounds.size.height + ButtonInset * 2); return CGRectContainsPoint(newArea, point);
}
@end

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
相关资源
相似解决方案