扩大Button点击事件
.h文件
#import <UIKit/UIKit.h>
@interface UIButton (XXHitTestInsets)
@property (nonatomic, assign) UIEdgeInsets xx_hitTestInsets;
@end
.m文件
#import "UIButton+XXHitTestInsets.h"
#import <objc/runtime.h>
@implementation UIButton (XXHitTestInsets)
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
CGRect b = self.bounds;
UIEdgeInsets areaForTouch = self.xx_hitTestInsets;
CGRect expandRect = CGRectMake(b.origin.x - areaForTouch.left,
b.origin.y - areaForTouch.top,
b.size.width + areaForTouch.left + areaForTouch.right,
b.size.height + areaForTouch.top + areaForTouch.bottom);
return CGRectContainsPoint(expandRect, point);
}
@end
网友评论