使用category,来给UIButton设置一个较大的点击区
@interface ExtendedHitButton: UIButton + (instancetype) extendedHitButton; - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; @end @implementation ExtendedHitButton + (instancetype) extendedHitButton { return (ExtendedHitButton *) [ExtendedHitButton buttonWithType:UIButtonTypeCustom]; } - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { CGRect relativeFrame = self.bounds; UIEdgeInsets hitTestEdgeInsets = UIEdgeInsetsMake(-44, -44, -44, -44); CGRect hitFrame = UIEdgeInsetsInsetRect(relativeFrame, hitTestEdgeInsets); return CGRectContainsPoint(hitFrame, point); } @end
链接:http://stackoverflow.com/questions/808503/uibutton-making-the-hit-area-larger-than-the-default-hit-area