From 36764a3d714781e321cbc7c8ce43bcf15b632cd4 Mon Sep 17 00:00:00 2001 From: chuckboris Date: Tue, 23 Jan 2018 11:13:59 +0100 Subject: [PATCH 1/9] Update MBCircularProgressBarView.m Adapt to frame size change --- Pod/Classes/MBCircularProgressBarView.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 8fecc39..05caa19 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -69,6 +69,10 @@ -(void)initView:(CGRect)frame{ [self setCountdown:NO]; } +- (void)layoutSubviews { + [self.layer setNeedsDisplay]; +} + #pragma mark - Getters and Setters for layer properties -(void)setShowValueString:(BOOL)showValueString{ From 8f674c6c8bbda12d2165675556716ea1a45fb849 Mon Sep 17 00:00:00 2001 From: Wellington Moreno Date: Sat, 3 Feb 2018 13:51:00 -0800 Subject: [PATCH 2/9] Adds support for counter-clockwise progress --- Pod/Classes/MBCircularProgressBarLayer.h | 6 ++++++ Pod/Classes/MBCircularProgressBarLayer.m | 24 +++++++++++++++++++----- Pod/Classes/MBCircularProgressBarView.h | 7 ++++++- Pod/Classes/MBCircularProgressBarView.m | 9 +++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) 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 From ba63be71b4f43e2d30b0ff03e053b4e78cc6497c Mon Sep 17 00:00:00 2001 From: Boris Ulicny Date: Mon, 18 Feb 2019 13:41:01 +0100 Subject: [PATCH 3/9] Unit string shown under numerical value --- Pod/Classes/MBCircularProgressBarLayer.m | 95 ++++++++++++------------ 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 0b1718a..6864fd9 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -57,7 +57,7 @@ - (void) drawInContext:(CGContextRef) context{ [self drawProgressBar:rect context:context]; if (self.showValueString){ - [self drawText:rect context:context]; + [self drawText:rect.size context:context]; } UIGraphicsPopContext(); @@ -143,52 +143,55 @@ - (void)drawProgressBar:(CGRect)rect context:(CGContextRef)c{ CGPathRelease(strokedArc); } -- (void)drawText:(CGRect)rect context:(CGContextRef)c{ - NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy; - textStyle.alignment = NSTextAlignmentLeft; - - CGFloat valueFontSize = self.valueFontSize == -1 ? CGRectGetHeight(rect)/5 : self.valueFontSize; - - NSDictionary* valueFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:valueFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; - - NSMutableAttributedString *text = [NSMutableAttributedString new]; - - NSString *formatString = [NSString stringWithFormat:@"%%.%df", (int)self.decimalPlaces]; - - NSString* textToPresent; - if (self.countdown) { - textToPresent = [NSString stringWithFormat:formatString, (self.maxValue - self.value)]; - } else { - textToPresent = [NSString stringWithFormat:formatString, self.value]; - } - NSAttributedString* value = [[NSAttributedString alloc] initWithString:textToPresent +- (void)drawText:(CGSize)rectSize context:(CGContextRef)c +{ + NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.new; + textStyle.alignment = NSTextAlignmentCenter; + + CGFloat valueFontSize = self.valueFontSize == -1 ? rectSize.height/5 : self.valueFontSize; + + NSDictionary* valueFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:valueFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + + NSMutableAttributedString *text = [NSMutableAttributedString new]; + + NSString *formatString = [NSString stringWithFormat:@"%%.%df", (int)self.decimalPlaces]; + + NSString* textToPresent; + if (self.countdown) { + textToPresent = [NSString stringWithFormat:formatString, (self.maxValue - self.value)]; + } else { + textToPresent = [NSString stringWithFormat:formatString, self.value]; + } + NSAttributedString* value = [[NSAttributedString alloc] initWithString:textToPresent attributes:valueFontAttributes]; - [text appendAttributedString:value]; - - // set the decimal font size - NSUInteger decimalLocation = [text.string rangeOfString:@"."].location; - if (decimalLocation != NSNotFound){ - NSDictionary* valueDecimalFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:self.valueDecimalFontSize == -1 ? valueFontSize : self.valueDecimalFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; - NSRange decimalRange = NSMakeRange(decimalLocation, text.length - decimalLocation); - [text setAttributes:valueDecimalFontAttributes range:decimalRange]; - } - - // ad the unit only if specified - if (self.showUnitString) { - NSDictionary* unitFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.unitFontName size:self.unitFontSize == -1 ? CGRectGetHeight(rect)/7 : self.unitFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; - - NSAttributedString* unit = - [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", self.unitString] attributes:unitFontAttributes]; - [text appendAttributedString:unit]; - } - - CGSize percentSize = [text size]; - CGPoint textCenter = CGPointMake( - CGRectGetMidX(rect)-percentSize.width/2 + self.textOffset.x, - CGRectGetMidY(rect)-percentSize.height/2 + self.textOffset.y - ); - - [text drawAtPoint:textCenter]; + [text appendAttributedString:value]; + + // set the decimal font size + NSUInteger decimalLocation = [text.string rangeOfString:@"."].location; + if (decimalLocation != NSNotFound){ + NSDictionary* valueDecimalFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:self.valueDecimalFontSize == -1 ? valueFontSize : self.valueDecimalFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + NSRange decimalRange = NSMakeRange(decimalLocation, text.length - decimalLocation); + [text setAttributes:valueDecimalFontAttributes range:decimalRange]; + } + + // ad the unit only if specified + if (self.showUnitString) { + NSDictionary* unitFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.unitFontName size:self.unitFontSize == -1 ? rectSize.height/7 : self.unitFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + + NSAttributedString* unit = + [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@", self.unitString] attributes:unitFontAttributes]; + [text appendAttributedString:unit]; + } + + CGSize percentSize = [text size]; + CGPoint textCenter = CGPointMake( + rectSize.width/2-percentSize.width/2 + self.textOffset.x, + rectSize.height/2-percentSize.height/2 + self.textOffset.y + ); + + CGRect rect = { textCenter, percentSize }; + + [text drawInRect:rect]; } #pragma mark - Override methods to support animations From 5d51339a87a68f30fef4ad80b7f0c16c34ca47e2 Mon Sep 17 00:00:00 2001 From: Boris Ulicny Date: Wed, 13 Nov 2019 17:26:31 +0100 Subject: [PATCH 4/9] Replaced font name properties with font properties, allowing better control over fonts(weight). Has to be done in code though, because xCode does not support IBInspectable for UIFont. Solves iOS 13 situation where fontWithName returned wrong font. --- Pod/Classes/MBCircularProgressBarLayer.h | 4 ++-- Pod/Classes/MBCircularProgressBarLayer.m | 10 +++++----- Pod/Classes/MBCircularProgressBarView.h | 4 ++-- Pod/Classes/MBCircularProgressBarView.m | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 3465f00..155c682 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -127,12 +127,12 @@ typedef NS_ENUM(NSInteger, MBCircularProgressBarAppearanceType) { /** * The font size of the unit text [0,∞) */ -@property (nonatomic,copy) NSString *unitFontName; +@property (nonatomic,copy) UIFont *unitFont; /** * The name of the font of the unit string */ -@property (nonatomic,copy) NSString *valueFontName; +@property (nonatomic,copy) UIFont *valueFont; /** * Should show unit screen diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 6864fd9..661adef 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -32,8 +32,8 @@ @implementation MBCircularProgressBarLayer @dynamic progressAppearanceType; @dynamic decimalPlaces; @dynamic valueDecimalFontSize; -@dynamic unitFontName; -@dynamic valueFontName; +@dynamic unitFont; +@dynamic valueFont; @dynamic showUnitString; @dynamic showValueString; @dynamic textOffset; @@ -150,7 +150,7 @@ - (void)drawText:(CGSize)rectSize context:(CGContextRef)c CGFloat valueFontSize = self.valueFontSize == -1 ? rectSize.height/5 : self.valueFontSize; - NSDictionary* valueFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:valueFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + NSDictionary* valueFontAttributes = @{NSFontAttributeName: [self.valueFont fontWithSize:valueFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; NSMutableAttributedString *text = [NSMutableAttributedString new]; @@ -169,14 +169,14 @@ - (void)drawText:(CGSize)rectSize context:(CGContextRef)c // set the decimal font size NSUInteger decimalLocation = [text.string rangeOfString:@"."].location; if (decimalLocation != NSNotFound){ - NSDictionary* valueDecimalFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:self.valueDecimalFontSize == -1 ? valueFontSize : self.valueDecimalFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + NSDictionary* valueDecimalFontAttributes = @{NSFontAttributeName: [self.valueFont fontWithSize:self.valueDecimalFontSize == -1 ? valueFontSize : self.valueDecimalFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; NSRange decimalRange = NSMakeRange(decimalLocation, text.length - decimalLocation); [text setAttributes:valueDecimalFontAttributes range:decimalRange]; } // ad the unit only if specified if (self.showUnitString) { - NSDictionary* unitFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.unitFontName size:self.unitFontSize == -1 ? rectSize.height/7 : self.unitFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; + NSDictionary* unitFontAttributes = @{NSFontAttributeName: [self.unitFont fontWithSize:self.unitFontSize == -1 ? rectSize.height/7 : self.unitFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle}; NSAttributedString* unit = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@", self.unitString] attributes:unitFontAttributes]; diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index 425de6f..b517ed4 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -43,7 +43,7 @@ IB_DESIGNABLE /** * The name of the font of the value string */ -@property (nonatomic,copy) IBInspectable NSString *valueFontName; +@property (nonatomic,copy) IBInspectable UIFont *valueFont; /** * The font size of the value text [0,∞) @@ -63,7 +63,7 @@ IB_DESIGNABLE /** * The name of the font of the unit string */ -@property (nonatomic,copy) IBInspectable NSString *unitFontName; +@property (nonatomic,copy) IBInspectable UIFont *unitFont; /** * The font size of the unit text [0,∞) diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 05caa19..5019fa9 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -63,9 +63,9 @@ -(void)initView:(CGRect)frame{ [self setDecimalPlaces:0]; [self setShowUnitString:YES]; [self setShowValueString:YES]; - [self setValueFontName:@"HelveticaNeue-Thin"]; + [self setValueFont:[UIFont systemFontOfSize:100]]; [self setTextOffset:CGPointMake(0, 0)]; - [self setUnitFontName:@"HelveticaNeue-Thin"]; + [self setUnitFont:[UIFont systemFontOfSize:30 weight:UIFontWeightThin]]; [self setCountdown:NO]; } @@ -269,20 +269,20 @@ -(CGFloat)valueDecimalFontSize{ return self.progressLayer.valueDecimalFontSize; } --(void)setUnitFontName:(NSString *)unitFontName{ - self.progressLayer.unitFontName = unitFontName; +-(void)setUnitFont:(UIFont *)unitFont{ + self.progressLayer.unitFont = unitFont; } --(NSString *)unitFontName{ - return self.progressLayer.unitFontName; +-(UIFont *)unitFont{ + return self.progressLayer.unitFont; } --(void)setValueFontName:(NSString *)valueFontName{ - self.progressLayer.valueFontName = valueFontName; +-(void)setValueFont:(UIFont *)valueFont{ + self.progressLayer.valueFont = valueFont; } --(NSString *)valueFontName{ - return self.progressLayer.valueFontName; +-(UIFont *)valueFont{ + return self.progressLayer.valueFont; } -(void)setShowUnitString:(BOOL)showUnitString{ From cbc4890b6a951139f54de966511d9c6e3b936238 Mon Sep 17 00:00:00 2001 From: chuckboris Date: Wed, 13 Nov 2019 17:47:28 +0100 Subject: [PATCH 5/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bcb1dc0..294b123 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,9 @@ value | CGFloat | The value to be displayed in the center | [0,maxValue] maxValue | CGFloat | The maximum possible value, used to calculate the progress (value/maxValue) | [0,∞) showValueString | BOOL | Should show value string | showUnitString | BOOL | Should show unit string | -valueFontName | NSString | The name of the font of the value string | Any valid font name +valueFont | UIFont | The font of the value string | Any valid font valueFontSize | CGFloat | The font size of the value text | [0,∞) -valueFontName | NSString | The name of the font of the unit string | Any valid font name +unitFont | UIFont | The font of the unit string | Any valid font unitFontSize | CGFloat | The font size of the unit text | [0,∞) unitString | NSString | The string that represents the units, usually % | fontColor | UIColor | The color of the value and unit text | From 399c622b7f9b031dafa50baf0f10a6ee24ec07c4 Mon Sep 17 00:00:00 2001 From: Tim Gymnich Date: Thu, 15 Oct 2020 14:41:45 +0200 Subject: [PATCH 6/9] Added swift package manager support --- .gitignore | 2 ++ Package.swift | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Package.swift diff --git a/.gitignore b/.gitignore index c964cd8..6ac6f61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Xcode # build/ +.build/ +.swiftpm/ *.pbxuser !default.pbxuser *.mode1v3 diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..3fb11d7 --- /dev/null +++ b/Package.swift @@ -0,0 +1,25 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "MBCircularProgressBar", + platforms: [.iOS(.v9)], + products: [ + .library(name: "MBCircularProgressBar", targets: ["MBCircularProgressBar"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "MBCircularProgressBar", + dependencies: [], + path: "Pod/Classes", + publicHeadersPath: ".") + ] +) From 1c7eb6e24e119ef3b53378af435d949419f2c7c6 Mon Sep 17 00:00:00 2001 From: Boris Ulicny Date: Wed, 9 Jun 2021 11:55:38 +0200 Subject: [PATCH 7/9] added import needed for spm --- Pod/Classes/MBCircularProgressBarLayer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 155c682..7b84bd5 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -7,6 +7,7 @@ // @import QuartzCore; +@import UIKit; typedef NS_ENUM(NSInteger, MBCircularProgressBarAppearanceType) { MBCircularProgressBarAppearanceTypeOverlaysEmptyLine = 0, From 9bf11608e798ab97d1635833fabf67edf7f4382b Mon Sep 17 00:00:00 2001 From: Boris Ulicny Date: Mon, 21 Jun 2021 14:19:17 +0200 Subject: [PATCH 8/9] fix for counter-clockwise direction --- Pod/Classes/MBCircularProgressBarLayer.m | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index 64c1b92..ba303d5 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -122,24 +122,27 @@ - (void)drawProgressBar:(CGRect)rect context:(CGContextRef)c{ CGMutablePathRef arc = CGPathCreateMutable(); - 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; + CGFloat rotation = ((-self.progressRotationAngle/100.f)*2.f+0.5)*M_PI; + CGFloat startAngle = (self.progressAngle/100.f)*M_PI - rotation; + CGFloat endAngle = -(self.progressAngle/100.f)*M_PI - rotation; + CGFloat valueAngle = (2.f*M_PI)*(self.progressAngle/100.f)*(100.f-100.f*self.value/self.maxValue)/100.f; - if (self.counterclockwise) + if (clockwise) { - startAngle = -(startAngle + M_PI); + CGPathAddArc(arc, NULL, + center.x, center.y, radius, + startAngle - valueAngle, + endAngle, + YES); + } else { + CGPathAddArc(arc, NULL, + center.x, center.y, radius, + endAngle + valueAngle, + startAngle, + NO); } - CGPathAddArc(arc, - NULL, - center.x, - center.y, - radius, - startAngle, - endAngle, - clockwise); - CGPathRef strokedArc = CGPathCreateCopyByStrokingPath(arc, NULL, self.progressLineWidth, From cb118456723f24863763512ffe5fc82baf010f62 Mon Sep 17 00:00:00 2001 From: Boris Ulicny Date: Thu, 17 Feb 2022 15:26:29 +0100 Subject: [PATCH 9/9] Dark-mode support for the underlying layer (from https://github.com/heyarny/MBCircularProgressBar) --- Pod/Classes/MBCircularProgressBarView.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 4b9a277..7d2fdc7 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -74,6 +74,17 @@ - (void)layoutSubviews { [self.layer setNeedsDisplay]; } +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { + [super traitCollectionDidChange:previousTraitCollection]; + + if (@available(iOS 13.0, *)) { + if ([previousTraitCollection hasDifferentColorAppearanceComparedToTraitCollection: self.traitCollection]) { + // redraw layer (dark-mode) + [self.layer setNeedsDisplay]; + } + } +} + #pragma mark - Getters and Setters for layer properties -(void)setShowValueString:(BOOL)showValueString{