From ea7812bad839de223f95f6e818525f60883a6b65 Mon Sep 17 00:00:00 2001 From: Denis Morozov Date: Sun, 5 Mar 2017 18:37:29 +0300 Subject: [PATCH] Add ability to customize corner radius of the lines for the BEMBoxTypeSquare box type --- Classes/BEMCheckBox.h | 4 ++++ Classes/BEMCheckBox.m | 8 ++++++++ Classes/BEMPathManager.h | 4 ++++ Classes/BEMPathManager.m | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 Classes/BEMCheckBox.h mode change 100644 => 100755 Classes/BEMCheckBox.m mode change 100644 => 100755 Classes/BEMPathManager.h mode change 100644 => 100755 Classes/BEMPathManager.m diff --git a/Classes/BEMCheckBox.h b/Classes/BEMCheckBox.h old mode 100644 new mode 100755 index ffb29a6..161ac0b --- a/Classes/BEMCheckBox.h +++ b/Classes/BEMCheckBox.h @@ -82,6 +82,10 @@ typedef NS_ENUM(NSInteger, BEMAnimationType) { */ @property (nonatomic) IBInspectable CGFloat lineWidth; +/** The corner radius which is applied to the box when the boxType is BEMBoxTypeSquare. Default to 3.0. + */ +@property (nonatomic) IBInspectable CGFloat cornerRadius; + /** The duration in seconds of the animation when the check box switches from on and off. Default to 0.5. */ @property (nonatomic) IBInspectable CGFloat animationDuration; diff --git a/Classes/BEMCheckBox.m b/Classes/BEMCheckBox.m old mode 100644 new mode 100755 index bd177b7..6836d21 --- a/Classes/BEMCheckBox.m +++ b/Classes/BEMCheckBox.m @@ -72,6 +72,7 @@ - (void)commonInit { _onCheckColor = [UIColor colorWithRed:0 green:122.0/255.0 blue:255/255 alpha:1]; _tintColor = [UIColor lightGrayColor]; _lineWidth = 2.0; + _cornerRadius = 3.0; _animationDuration = 0.5; _minimumTouchSize = CGSizeMake(44, 44); _onAnimationType = BEMAnimationTypeStroke; @@ -87,6 +88,7 @@ - (void)commonInit { - (void)initPathManager { _pathManager = [BEMPathManager new]; _pathManager.lineWidth = _lineWidth; + _pathManager.cornerRadius = _cornerRadius; _pathManager.boxType = _boxType; } @@ -167,6 +169,12 @@ - (void)setLineWidth:(CGFloat)lineWidth { [self reload]; } +- (void)setCornerRadius:(CGFloat)cornerRadius { + _cornerRadius = cornerRadius; + _pathManager.cornerRadius = cornerRadius; + [self reload]; +} + - (void)setOffAnimationType:(BEMAnimationType)offAnimationType { _offAnimationType = offAnimationType; } diff --git a/Classes/BEMPathManager.h b/Classes/BEMPathManager.h old mode 100644 new mode 100755 index 9bf44b2..8dacd90 --- a/Classes/BEMPathManager.h +++ b/Classes/BEMPathManager.h @@ -22,6 +22,10 @@ */ @property (nonatomic) CGFloat lineWidth; +/** The corner radius of the path when the boxType is BEMBoxTypeSquare. + */ +@property (nonatomic) CGFloat cornerRadius; + /** The type of box. * Depending on the box type, paths may be created differently * @see BEMBoxType diff --git a/Classes/BEMPathManager.m b/Classes/BEMPathManager.m old mode 100644 new mode 100755 index ffb8f5f..ce5ab44 --- a/Classes/BEMPathManager.m +++ b/Classes/BEMPathManager.m @@ -16,7 +16,7 @@ - (UIBezierPath *)pathForBox { UIBezierPath* path; switch (self.boxType) { case BEMBoxTypeSquare: - path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.size, self.size) cornerRadius:3.0]; + path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.size, self.size) cornerRadius:self.cornerRadius]; [path applyTransform:CGAffineTransformRotate(CGAffineTransformIdentity, M_PI * 2.5)]; [path applyTransform:CGAffineTransformMakeTranslation(self.size, 0)]; break;