Skip to content

Instantly share code, notes, and snippets.

@sviataslau
Last active December 11, 2015 19:38
Show Gist options
  • Save sviataslau/4649886 to your computer and use it in GitHub Desktop.
Save sviataslau/4649886 to your computer and use it in GitHub Desktop.
iOS button with enlarged tap area.
#import <UIKit/UIKit.h>
@interface EnlargedTapButton : UIButton
@end
#import "EnlargedTapButton.h"
#define MARGIN 30.0
@implementation EnlargedTapButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (BOOL)point:(CGPoint)point insideWithMargin: (float)margin {
CGRect rect = CGRectInset(self.bounds, -margin, -margin);
return CGRectContainsPoint(rect, point);
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
BOOL touchInside = [self point:point insideWithMargin: MARGIN];
return touchInside;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment