From f6fb51b182972f0664ceb0dfbcc8a1e3d559393c Mon Sep 17 00:00:00 2001 From: anIOSer Date: Wed, 8 Jun 2016 16:56:52 +0800 Subject: [PATCH] add Circle with Where to Start --- DACircularProgress/DACircularProgressView.h | 3 ++- DACircularProgress/DACircularProgressView.m | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) mode change 100644 => 100755 DACircularProgress/DACircularProgressView.h mode change 100644 => 100755 DACircularProgress/DACircularProgressView.m diff --git a/DACircularProgress/DACircularProgressView.h b/DACircularProgress/DACircularProgressView.h old mode 100644 new mode 100755 index 391b449..218ad54 --- a/DACircularProgress/DACircularProgressView.h +++ b/DACircularProgress/DACircularProgressView.h @@ -17,7 +17,7 @@ @property(nonatomic) CGFloat thicknessRatio UI_APPEARANCE_SELECTOR; @property(nonatomic) NSInteger clockwiseProgress UI_APPEARANCE_SELECTOR; // Can not use BOOL with UI_APPEARANCE_SELECTOR :-( @property(nonatomic) CGFloat progress; - +@property(nonatomic) CGFloat proStart;//Where to Start the Circle @property(nonatomic) CGFloat indeterminateDuration UI_APPEARANCE_SELECTOR; @property(nonatomic) NSInteger indeterminate UI_APPEARANCE_SELECTOR; // Can not use BOOL with UI_APPEARANCE_SELECTOR :-( @@ -26,3 +26,4 @@ - (void)setProgress:(CGFloat)progress animated:(BOOL)animated initialDelay:(CFTimeInterval)initialDelay withDuration:(CFTimeInterval)duration; @end + diff --git a/DACircularProgress/DACircularProgressView.m b/DACircularProgress/DACircularProgressView.m old mode 100644 new mode 100755 index ec4e30f..af36fcf --- a/DACircularProgress/DACircularProgressView.m +++ b/DACircularProgress/DACircularProgressView.m @@ -19,7 +19,7 @@ @interface DACircularProgressLayer : CALayer @property(nonatomic) CGFloat thicknessRatio; @property(nonatomic) CGFloat progress; @property(nonatomic) NSInteger clockwiseProgress; - +@property(nonatomic) CGFloat proStart; @end @implementation DACircularProgressLayer @@ -31,6 +31,7 @@ @implementation DACircularProgressLayer @dynamic thicknessRatio; @dynamic progress; @dynamic clockwiseProgress; +@dynamic proStart; + (BOOL)needsDisplayForKey:(NSString *)key { @@ -43,6 +44,7 @@ + (BOOL)needsDisplayForKey:(NSString *)key - (void)drawInContext:(CGContextRef)context { + CGRect rect = self.bounds; CGPoint centerPoint = CGPointMake(rect.size.width / 2.0f, rect.size.height / 2.0f); CGFloat radius = MIN(rect.size.height, rect.size.width) / 2.0f; @@ -50,11 +52,13 @@ - (void)drawInContext:(CGContextRef)context BOOL clockwise = (self.clockwiseProgress != 0); CGFloat progress = MIN(self.progress, 1.0f - FLT_EPSILON); + CGFloat proStart = self.proStart ? self.proStart : 3.0f *M_PI_2; + CGFloat radians = 0; if (clockwise) { - radians = (float)((progress * 2.0f * M_PI) - M_PI_2); + radians = (float)((progress * 2.0f * M_PI) - (2.0f*M_PI - self.proStart)); } else { - radians = (float)(3 * M_PI_2 - (progress * 2.0f * M_PI)); + radians = (float)(proStart - (progress * 2.0f * M_PI)); //修改的地方 (progress * 2.0f * M_PI 起始位置 } CGContextSetFillColorWithColor(context, self.trackTintColor.CGColor); @@ -70,7 +74,7 @@ - (void)drawInContext:(CGContextRef)context CGContextSetFillColorWithColor(context, self.progressTintColor.CGColor); CGMutablePathRef progressPath = CGPathCreateMutable(); CGPathMoveToPoint(progressPath, NULL, centerPoint.x, centerPoint.y); - CGPathAddArc(progressPath, NULL, centerPoint.x, centerPoint.y, radius, (float)(3.0f * M_PI_2), radians, !clockwise); + CGPathAddArc(progressPath, NULL, centerPoint.x, centerPoint.y, radius, (float)proStart, radians, !clockwise); //修改画园的起始位置 CGPathCloseSubpath(progressPath); CGContextAddPath(context, progressPath); CGContextFillPath(context); @@ -287,6 +291,15 @@ - (void)setThicknessRatio:(CGFloat)thicknessRatio [self.circularProgressLayer setNeedsDisplay]; } +-(CGFloat)proStart{ + return self.circularProgressLayer.proStart; +} + +-(void)setProStart:(CGFloat)proStart{ + self.circularProgressLayer.proStart = proStart; + [self.circularProgressLayer setNeedsDisplay]; +} + - (NSInteger)indeterminate { CAAnimation *spinAnimation = [self.layer animationForKey:@"indeterminateAnimation"];