From c40d0cba776bc66e8d96bd7b0b666f7c4abab5e1 Mon Sep 17 00:00:00 2001 From: staz1000 <> Date: Tue, 9 Oct 2018 23:09:09 +0100 Subject: [PATCH] Added support for animating progressColor & progressStrokeColor --- Pod/Classes/MBCircularProgressBarLayer.h | 4 +-- Pod/Classes/MBCircularProgressBarLayer.m | 40 ++++++++++++------------ Pod/Classes/MBCircularProgressBarView.m | 8 ++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 3465f00..d5bb1d8 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -83,12 +83,12 @@ typedef NS_ENUM(NSInteger, MBCircularProgressBarAppearanceType) { /** * The color of the progress bar */ -@property (nonatomic,strong) UIColor *progressColor; +@property (nonatomic,assign) CGColorRef progressColor; /** * The color of the progress bar frame */ -@property (nonatomic,strong) UIColor *progressStrokeColor; +@property (nonatomic,assign) CGColorRef progressStrokeColor; /** * The shape of the progress bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2} diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 0b1718a..f7e7d6d 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -135,8 +135,8 @@ - (void)drawProgressBar:(CGRect)rect context:(CGContextRef)c{ CGContextAddPath(c, strokedArc); - CGContextSetFillColorWithColor(c, self.progressColor.CGColor); - CGContextSetStrokeColorWithColor(c, self.progressStrokeColor.CGColor); + CGContextSetFillColorWithColor(c, self.progressColor); + CGContextSetStrokeColorWithColor(c, self.progressStrokeColor); CGContextDrawPath(c, kCGPathFillStroke); CGPathRelease(arc); @@ -193,28 +193,28 @@ - (void)drawText:(CGRect)rect context:(CGContextRef)c{ #pragma mark - Override methods to support animations ++ (BOOL)isCustomAnimationKey:(NSString *)key { + return [key isEqualToString:@"value"] || [key isEqualToString:@"progressColor"] || [key isEqualToString:@"progressStrokeColor"]; +} + + (BOOL)needsDisplayForKey:(NSString *)key { - if ([key isEqualToString:@"value"]) { - return YES; - } + if ([self isCustomAnimationKey:key]) return true; return [super needsDisplayForKey:key]; } - -- (id)actionForKey:(NSString *)event{ - if ([self presentationLayer] != nil) { - if ([event isEqualToString:@"value"]) { - id animation = [super actionForKey:@"backgroundColor"]; - - if (animation == nil || [animation isEqual:[NSNull null]]) - { - [self setNeedsDisplay]; - return [NSNull null]; - } - [animation setKeyPath:event]; - [animation setFromValue:[self.presentationLayer valueForKey:@"value"]]; - [animation setToValue:nil]; - return animation; + +- (id)actionForKey:(NSString *)event { + + if ([self presentationLayer] != nil && [[self class] isCustomAnimationKey:event]) { + id animation = [super actionForKey:@"backgroundColor"]; + + if (animation == nil || [animation isEqual:[NSNull null]]) { + [self setNeedsDisplay]; + return [NSNull null]; } + [animation setKeyPath:event]; + [animation setFromValue:[self.presentationLayer valueForKey:event]]; + [animation setToValue:nil]; + return animation; } return [super actionForKey:event]; diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 8fecc39..4f5f86d 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -131,11 +131,11 @@ -(CGFloat)emptyLineWidth{ } -(void)setProgressColor:(UIColor*)color{ - self.progressLayer.progressColor = color; + self.progressLayer.progressColor = color.CGColor; } -(UIColor*)progressColor{ - return self.progressLayer.progressColor; + return [UIColor colorWithCGColor: self.progressLayer.progressColor]; } -(void)setUnitFontSize:(CGFloat)unitFontSize{ @@ -171,11 +171,11 @@ -(UIColor*)fontColor{ } -(void)setProgressStrokeColor:(UIColor*)color{ - self.progressLayer.progressStrokeColor = color; + self.progressLayer.progressStrokeColor = color.CGColor; } -(UIColor*)progressStrokeColor{ - return self.progressLayer.progressStrokeColor; + return [UIColor colorWithCGColor: self.progressLayer.progressStrokeColor]; } -(void)setEmptyLineColor:(UIColor *)emptyLineColor{