Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase touch area if checkbox is smaller than 44pt #19

Merged
merged 3 commits into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add minimum touch size property, fix code style issues
  • Loading branch information
Jay Moore committed Apr 14, 2016
commit 95670f49de378b28064160a4546ce3ea1f880799
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, please remove the space before pointInside:

{
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