Kevin

Merge pull request #43 from vertigo/clockwise-circle-chart

Add ability for PNCircleChart to go clockwise 
@@ -15,13 +15,14 @@ @@ -15,13 +15,14 @@
15 @interface PNCircleChart : UIView 15 @interface PNCircleChart : UIView
16 16
17 -(void)strokeChart; 17 -(void)strokeChart;
18 -- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current; 18 +- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise;
19 19
20 @property (nonatomic, strong) UIColor *strokeColor; 20 @property (nonatomic, strong) UIColor *strokeColor;
21 @property (nonatomic, strong) UIColor *labelColor; 21 @property (nonatomic, strong) UIColor *labelColor;
22 @property (nonatomic, strong) NSNumber * total; 22 @property (nonatomic, strong) NSNumber * total;
23 @property (nonatomic, strong) NSNumber * current; 23 @property (nonatomic, strong) NSNumber * current;
24 @property (nonatomic, strong) NSNumber * lineWidth; 24 @property (nonatomic, strong) NSNumber * lineWidth;
  25 +@property (nonatomic) BOOL clockwise;
25 26
26 @property(nonatomic,strong) CAShapeLayer * circle; 27 @property(nonatomic,strong) CAShapeLayer * circle;
27 @property(nonatomic,strong) CAShapeLayer * circleBG; 28 @property(nonatomic,strong) CAShapeLayer * circleBG;
@@ -26,17 +26,20 @@ @@ -26,17 +26,20 @@
26 } 26 }
27 27
28 28
29 -- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current 29 +- (id)initWithFrame:(CGRect)frame andTotal:(NSNumber *)total andCurrent:(NSNumber *)current andClockwise:(BOOL)clockwise {
30 -{  
31 self = [super initWithFrame:frame]; 30 self = [super initWithFrame:frame];
32 31
33 if (self) { 32 if (self) {
34 _total = total; 33 _total = total;
35 _current = current; 34 _current = current;
36 _strokeColor = PNFreshGreen; 35 _strokeColor = PNFreshGreen;
  36 + _clockwise = clockwise;
  37 +
  38 + CGFloat startAngle = clockwise ? -90.0f : 270.0f;
  39 + CGFloat endAngle = clockwise ? -90.01f : 270.01f;
37 40
38 _lineWidth = [NSNumber numberWithFloat:8.0]; 41 _lineWidth = [NSNumber numberWithFloat:8.0];
39 - UIBezierPath* circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x,self.center.y) radius:self.frame.size.height*0.5 startAngle:DEGREES_TO_RADIANS(270) endAngle:DEGREES_TO_RADIANS(270.01) clockwise:NO]; 42 + UIBezierPath* circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x,self.center.y) radius:self.frame.size.height*0.5 startAngle:DEGREES_TO_RADIANS(startAngle) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:clockwise];
40 43
41 _circle = [CAShapeLayer layer]; 44 _circle = [CAShapeLayer layer];
42 _circle.path = circlePath.CGPath; 45 _circle.path = circlePath.CGPath;
@@ -127,7 +127,7 @@ @@ -127,7 +127,7 @@
127 circleChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0]; 127 circleChartLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:23.0];
128 circleChartLabel.textAlignment = NSTextAlignmentCenter; 128 circleChartLabel.textAlignment = NSTextAlignmentCenter;
129 129
130 - PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60]]; 130 + PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60] andClockwise:NO];
131 circleChart.backgroundColor = [UIColor clearColor]; 131 circleChart.backgroundColor = [UIColor clearColor];
132 [circleChart setStrokeColor:PNGreen]; 132 [circleChart setStrokeColor:PNGreen];
133 [circleChart strokeChart]; 133 [circleChart strokeChart];
@@ -88,7 +88,7 @@ You will need LLVM 3.0 or later in order to build PNChart. @@ -88,7 +88,7 @@ You will need LLVM 3.0 or later in order to build PNChart.
88 88
89 //For CircleChart 89 //For CircleChart
90 90
91 -PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60]]; 91 +PNCircleChart * circleChart = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 80.0, SCREEN_WIDTH, 100.0) andTotal:[NSNumber numberWithInt:100] andCurrent:[NSNumber numberWithInt:60] andClockwise:NO];
92 circleChart.backgroundColor = [UIColor clearColor]; 92 circleChart.backgroundColor = [UIColor clearColor];
93 [circleChart setStrokeColor:PNGreen]; 93 [circleChart setStrokeColor:PNGreen];
94 [circleChart strokeChart]; 94 [circleChart strokeChart];