From 685698581fb74721230ae1213e6a95857daf7d6c Mon Sep 17 00:00:00 2001 From: Jay Moore Date: Thu, 14 Apr 2016 11:02:07 -0400 Subject: [PATCH 1/3] increase touch area if checkbox is smaller than 44pt --- Classes/BEMCheckBox.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Classes/BEMCheckBox.m b/Classes/BEMCheckBox.m index d4c613c..e5490c5 100644 --- a/Classes/BEMCheckBox.m +++ b/Classes/BEMCheckBox.m @@ -172,6 +172,27 @@ - (void)handleTapCheckBox:(UITapGestureRecognizer *)recognizer { } } +// increase touch area +- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event; +{ + BOOL found = [super pointInside:point withEvent:event]; + + CGFloat minimumSize = 44; + CGFloat w = self.frame.size.width; + CGFloat h = self.frame.size.height; + + if (found == NO && (w < minimumSize || h < minimumSize)) { + CGFloat increaseW = minimumSize - w; + CGFloat increaseH = minimumSize - h; + + CGRect rect = CGRectInset(self.bounds, (-increaseW/2), (-increaseH/2)); + + found = CGRectContainsPoint(rect, point); + } + + return found; +} + #pragma mark - Helper methods - #pragma mark Drawings - (void)drawRect:(CGRect)rect { From 95670f49de378b28064160a4546ce3ea1f880799 Mon Sep 17 00:00:00 2001 From: Jay Moore Date: Thu, 14 Apr 2016 16:53:18 -0400 Subject: [PATCH 2/3] add minimum touch size property, fix code style issues --- Classes/BEMCheckBox.h | 4 ++++ Classes/BEMCheckBox.m | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Classes/BEMCheckBox.h b/Classes/BEMCheckBox.h index 6116be0..1f4a708 100644 --- a/Classes/BEMCheckBox.h +++ b/Classes/BEMCheckBox.h @@ -118,6 +118,10 @@ typedef NS_ENUM(NSInteger, BEMAnimationType) { */ @property (nonatomic) BEMAnimationType offAnimationType; +/** If the checkbox width or height is smaller than this value, the touch area will be increased. Allows for visually small checkboxes to still be easily tapped. Default: (44, 44) + */ +@property (assign, nonatomic) IBInspectable CGSize minimumTouchSize; + /** Set the state of the check box to On or Off, optionally animating the transition. */ - (void)setOn:(BOOL)on animated:(BOOL)animated; diff --git a/Classes/BEMCheckBox.m b/Classes/BEMCheckBox.m index e5490c5..7b3940c 100644 --- a/Classes/BEMCheckBox.m +++ b/Classes/BEMCheckBox.m @@ -59,6 +59,7 @@ - (void)commonInit { _tintColor = [UIColor lightGrayColor]; _lineWidth = 2.0; _animationDuration = 0.5; + _minimumTouchSize = CGSizeMake(44, 44); _onAnimationType = BEMAnimationTypeStroke; _offAnimationType = BEMAnimationTypeStroke; self.backgroundColor = [UIColor clearColor]; @@ -172,20 +173,20 @@ - (void)handleTapCheckBox:(UITapGestureRecognizer *)recognizer { } } -// increase touch area +#pragma mark Increase touch area - (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event; { BOOL found = [super pointInside:point withEvent:event]; - CGFloat minimumSize = 44; - CGFloat w = self.frame.size.width; - CGFloat h = self.frame.size.height; + CGSize minimumSize = self.minimumTouchSize; + CGFloat width = self.bounds.size.width; + CGFloat height = self.bounds.size.height; - if (found == NO && (w < minimumSize || h < minimumSize)) { - CGFloat increaseW = minimumSize - w; - CGFloat increaseH = minimumSize - h; + if (found == NO && (width < minimumSize.width || height < minimumSize.height)) { + CGFloat increaseWidth = minimumSize.width - width; + CGFloat increaseHeight = minimumSize.height - height; - CGRect rect = CGRectInset(self.bounds, (-increaseW/2), (-increaseH/2)); + CGRect rect = CGRectInset(self.bounds, (-increaseWidth / 2), (-increaseHeight / 2)); found = CGRectContainsPoint(rect, point); } From b614b93f9c7a038636fb83df988e037cb7b594ad Mon Sep 17 00:00:00 2001 From: Jay Moore Date: Thu, 14 Apr 2016 16:55:48 -0400 Subject: [PATCH 3/3] move method --- Classes/BEMCheckBox.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/BEMCheckBox.m b/Classes/BEMCheckBox.m index 7b3940c..b13172d 100644 --- a/Classes/BEMCheckBox.m +++ b/Classes/BEMCheckBox.m @@ -173,6 +173,8 @@ - (void)handleTapCheckBox:(UITapGestureRecognizer *)recognizer { } } +#pragma mark - Helper methods - + #pragma mark Increase touch area - (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event; { @@ -194,7 +196,6 @@ - (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *)event; return found; } -#pragma mark - Helper methods - #pragma mark Drawings - (void)drawRect:(CGRect)rect { [self setOn:self.on animated:NO];