自定义按钮类型CustomButton,继承UIButton,重写pointInside函数改变点击响应范围。
例如,按钮点击范围比实际高度上下增加6。
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