Skip to content

Commit

Permalink
add minimum touch size property, fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Moore committed Apr 14, 2016
1 parent 6856985 commit 95670f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Classes/BEMCheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions Classes/BEMCheckBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 95670f4

Please sign in to comment.