Kevin

Merge pull request #138 from dredful/master

Added additional initWithFrame methods to allow for chart options
... ... @@ -29,6 +29,30 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow;
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow
shadowColor:(UIColor *)backgroundShadowColor;
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow
shadowColor:(UIColor *)backgroundShadowColor
displayCountingLabel:(BOOL)displayCountingLabel;
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow
shadowColor:(UIColor *)backgroundShadowColor
displayCountingLabel:(BOOL)displayCountingLabel
overrideLineWidth:(NSNumber *)overrideLineWidth;
@property (strong, nonatomic) UICountingLabel *countingLabel;
@property (nonatomic) UIColor *strokeColor;
@property (nonatomic) UIColor *strokeColorGradientStart;
... ... @@ -43,4 +67,6 @@ typedef NS_ENUM (NSUInteger, PNChartFormatType) {
@property (nonatomic) CAShapeLayer *gradientMask;
@property (nonatomic) CAShapeLayer *circleBackground;
@property (nonatomic) BOOL displayCountingLabel;
@end
... ...
... ... @@ -13,12 +13,53 @@
@implementation PNCircleChart
- (id)initWithFrame:(CGRect)frame total:(NSNumber *)total current:(NSNumber *)current clockwise:(BOOL)clockwise shadow:(BOOL)hasBackgroundShadow {
return [self initWithFrame:frame
total:total
current:current
clockwise:clockwise
shadow:shadow
shadowColor:PNGreen
displayCountingLabel:YES
overrideLineWidth:@8.0f];
}
- (id)initWithFrame:(CGRect)frame total:(NSNumber *)total current:(NSNumber *)current clockwise:(BOOL)clockwise shadow:(BOOL)hasBackgroundShadow shadowColor:(UIColor *)backgroundShadowColor {
return [self initWithFrame:frame
total:total
current:current
clockwise:clockwise
shadow:shadow
shadowColor:backgroundShadowColor
displayCountingLabel:YES
overrideLineWidth:@8.0f];
}
- (id)initWithFrame:(CGRect)frame total:(NSNumber *)total current:(NSNumber *)current clockwise:(BOOL)clockwise shadow:(BOOL)hasBackgroundShadow shadowColor:(UIColor *)backgroundShadowColor displayCountingLabel:(BOOL)displayCountingLabel {
return [self initWithFrame:frame
total:total
current:current
clockwise:clockwise
shadow:shadow
shadowColor:PNGreen
displayCountingLabel:displayCountingLabel
overrideLineWidth:@8.0f];
}
- (id)initWithFrame:(CGRect)frame
total:(NSNumber *)total
current:(NSNumber *)current
clockwise:(BOOL)clockwise
shadow:(BOOL)hasBackgroundShadow
shadowColor:(UIColor *)backgroundShadowColor
displayCountingLabel:(BOOL)displayCountingLabel
overrideLineWidth:(NSNumber *)overrideLineWidth
{
self = [super initWithFrame:frame];
... ... @@ -29,12 +70,15 @@
_duration = 1.0;
_chartType = PNChartFormatTypePercent;
_displayCountingLabel = displayCountingLabel;
CGFloat startAngle = clockwise ? -90.0f : 270.0f;
CGFloat endAngle = clockwise ? -90.01f : 270.01f;
_lineWidth = @8.0f;
_lineWidth = overrideLineWidth;
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.bounds.size.width/2.0f, self.bounds.size.height/2.0f)
radius:(self.frame.size.height * 0.5) - [_lineWidth floatValue]
radius:(self.frame.size.height * 0.5) - ([_lineWidth floatValue]/2.0f)
startAngle:DEGREES_TO_RADIANS(startAngle)
endAngle:DEGREES_TO_RADIANS(endAngle)
clockwise:clockwise];
... ... @@ -51,7 +95,7 @@
_circleBackground.lineCap = kCALineCapRound;
_circleBackground.fillColor = [UIColor clearColor].CGColor;
_circleBackground.lineWidth = [_lineWidth floatValue];
_circleBackground.strokeColor = (hasBackgroundShadow ? PNLightYellow.CGColor : [UIColor clearColor].CGColor);
_circleBackground.strokeColor = (hasBackgroundShadow ? backgroundShadowColor.CGColor : [UIColor clearColor].CGColor);
_circleBackground.strokeEnd = 1.0;
_circleBackground.zPosition = -1;
... ... @@ -65,7 +109,9 @@
[_countingLabel setBackgroundColor:[UIColor clearColor]];
[_countingLabel setCenter:CGPointMake(self.center.x, self.center.y)];
_countingLabel.method = UILabelCountingMethodEaseInOut;
[self addSubview:_countingLabel];;
if (_displayCountingLabel) {
[self addSubview:_countingLabel];
}
}
return self;
... ... @@ -76,6 +122,7 @@
{
// Add counting label
if (_displayCountingLabel) {
NSString *format;
switch (self.chartType) {
case PNChartFormatTypePercent:
... ... @@ -91,6 +138,7 @@
}
self.countingLabel.format = format;
[self addSubview:self.countingLabel];
}
// Add circle params
... ... @@ -172,7 +220,10 @@
}
[_circle addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
if (_displayCountingLabel) {
[self.countingLabel countFrom:fmin([_current floatValue], [_total floatValue]) to:fmin([current floatValue], [_total floatValue]) withDuration:self.duration];
}
_current = current;
}
... ...