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

Border padding feature is been added #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions Pod/Classes/MBCircularProgressBarLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 9 additions & 4 deletions Pod/Classes/MBCircularProgressBarLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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];
Expand Down
7 changes: 7 additions & 0 deletions Pod/Classes/MBCircularProgressBarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions Pod/Classes/MBCircularProgressBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down