Skip to content
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
6 changes: 6 additions & 0 deletions Pod/Classes/MBCircularProgressBarLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,11 @@ typedef NS_ENUM(NSInteger, MBCircularProgressBarAppearanceType) {
* Default is NO
*/
@property (nonatomic,assign) BOOL countdown;

/**
* Draw the progress circle in counter-clockwise fashion.
*/
@property (nonatomic,assign) BOOL counterclockwise;


@end
24 changes: 19 additions & 5 deletions Pod/Classes/MBCircularProgressBarLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ @implementation MBCircularProgressBarLayer
@dynamic showValueString;
@dynamic textOffset;
@dynamic countdown;
@dynamic counterclockwise;

#pragma mark - Drawing

Expand Down Expand Up @@ -120,11 +121,24 @@ - (void)drawProgressBar:(CGRect)rect context:(CGContextRef)c{
}

CGMutablePathRef arc = CGPathCreateMutable();
CGPathAddArc(arc, NULL,
center.x, center.y, radius,
(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,
YES);

CGFloat startAngle = (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;
CGFloat endAngle = -(self.progressAngle/100.f)*M_PI-((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI;
BOOL clockwise = !self.counterclockwise;

if (self.counterclockwise)
{
startAngle = -(startAngle + M_PI);
}

CGPathAddArc(arc,
NULL,
center.x,
center.y,
radius,
startAngle,
endAngle,
clockwise);

CGPathRef strokedArc =
CGPathCreateCopyByStrokingPath(arc, NULL,
Expand Down
7 changes: 6 additions & 1 deletion Pod/Classes/MBCircularProgressBarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ IB_DESIGNABLE


/**
* The bool value to apply to if its counddown or not
* The bool value to apply to if its countdown or not
*/
@property (nonatomic,assign) IBInspectable BOOL countdown;

/**
* The bool value to apply if the progress bar should rendered counter-clockwise.
*/
@property (nonatomic,assign) IBInspectable BOOL counterclockwise;

@end
9 changes: 9 additions & 0 deletions Pod/Classes/MBCircularProgressBarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ -(void)initView:(CGRect)frame{
[self setTextOffset:CGPointMake(0, 0)];
[self setUnitFontName:@"HelveticaNeue-Thin"];
[self setCountdown:NO];
[self setCounterclockwise:NO];
}

#pragma mark - Getters and Setters for layer properties
Expand Down Expand Up @@ -304,6 +305,14 @@ -(void)setCountdown:(BOOL)countdown {
-(BOOL)countdown {
return self.progressLayer.countdown;
}

-(void)setCounterclockwise:(BOOL)counterclockwise {
self.progressLayer.counterclockwise = counterclockwise;
}

-(BOOL)counterclockwise {
return self.progressLayer.counterclockwise;
}

#pragma mark - CALayer

Expand Down