From e042bbf48f26ea2f1f6af31bc44dbdbc97aad963 Mon Sep 17 00:00:00 2001 From: Ratul Sharker Date: Wed, 18 Jan 2017 19:23:00 +0600 Subject: [PATCH] Border padding feature is been added --- Pod/Classes/MBCircularProgressBarLayer.h | 7 +++++++ Pod/Classes/MBCircularProgressBarLayer.m | 13 +++++++++---- Pod/Classes/MBCircularProgressBarView.h | 7 +++++++ Pod/Classes/MBCircularProgressBarView.m | 9 +++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 561a9c1..1d0dcb7 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -140,4 +140,11 @@ */ @property (nonatomic,assign) BOOL countdown; +/** + * Circle radius padding from border + * of the UIView bounding box + * Default value is 0 + */ +@property (nonatomic, assign) CGFloat borderPadding; + @end diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 9e73d56..085281e 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -49,6 +49,9 @@ - (void) drawInContext:(CGContextRef) context{ UIGraphicsPushContext(context); CGSize size = CGRectIntegral(CGContextGetClipBoundingBox(context)).size; + size.height -= 2 * self.borderPadding; + size.width -= 2 * self.borderPadding; + [self drawEmptyBar:size context:context]; [self drawProgressBar:size context:context]; @@ -68,7 +71,8 @@ - (void)drawEmptyBar:(CGSize)rectSize context:(CGContextRef)c{ CGMutablePathRef arc = CGPathCreateMutable(); CGPathAddArc(arc, NULL, - rectSize.width/2, rectSize.height/2, + rectSize.width/2 + self.borderPadding, + rectSize.height/2 + self.borderPadding, MIN(rectSize.width,rectSize.height)/2 - self.progressLineWidth, (self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI, -(self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI, @@ -100,7 +104,8 @@ - (void)drawProgressBar:(CGSize)rectSize context:(CGContextRef)c{ CGMutablePathRef arc = CGPathCreateMutable(); CGPathAddArc(arc, NULL, - rectSize.width/2, rectSize.height/2, + rectSize.width/2 + self.borderPadding, + rectSize.height/2 + self.borderPadding, MIN(rectSize.width,rectSize.height)/2 - self.progressLineWidth, (self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI-(2.f*M_PI)*(self.progressAngle/100.f)*(100.f-100.f*self.value/self.maxValue)/100.f, -(self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI, @@ -167,8 +172,8 @@ - (void)drawText:(CGSize)rectSize context:(CGContextRef)c CGSize percentSize = [text size]; CGPoint textCenter = CGPointMake( - rectSize.width/2-percentSize.width/2 + self.textOffset.x, - rectSize.height/2-percentSize.height/2 + self.textOffset.y + rectSize.width/2-percentSize.width/2 + self.textOffset.x + self.borderPadding, + rectSize.height/2-percentSize.height/2 + self.textOffset.y + self.borderPadding ); [text drawAtPoint:textCenter]; diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index 0eb5fab..ee55a9a 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -136,4 +136,11 @@ IB_DESIGNABLE */ @property (nonatomic,assign) IBInspectable BOOL countdown; +/** + * Circle radius padding from border + * of the UIView bounding box + * Default value is 0 + */ +@property (nonatomic,assign) IBInspectable CGFloat borderPadding; + @end diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 5c6c71a..b74c897 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -64,6 +64,7 @@ -(void)initView:(CGRect)frame{ [self setTextOffset:CGPointMake(0, 0)]; [self setUnitFontName:@"HelveticaNeue-Thin"]; [self setCountdown:NO]; + [self setBorderPadding:0]; } #pragma mark - Getters and Setters for layer properties @@ -278,6 +279,14 @@ -(BOOL)countdown { return self.progressLayer.countdown; } +-(void)setBorderPadding:(CGFloat)borderPadding{ + self.progressLayer.borderPadding = borderPadding; +} + +-(CGFloat)borderPadding{ + return self.progressLayer.borderPadding; +} + #pragma mark - CALayer -(MBCircularProgressBarLayer*)progressLayer{