diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 3465f00..dd4515b 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -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 diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 0b1718a..45479dd 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -38,6 +38,7 @@ @implementation MBCircularProgressBarLayer @dynamic showValueString; @dynamic textOffset; @dynamic countdown; +@dynamic counterclockwise; #pragma mark - Drawing @@ -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, diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index 425de6f..9df5f31 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -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 diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 8fecc39..bf01a27 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -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 @@ -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