From ed1b54b363f1672fe36a2423cc970897b7836092 Mon Sep 17 00:00:00 2001 From: oriyentel Date: Mon, 14 Nov 2016 17:56:05 -0600 Subject: [PATCH 1/3] added properties for unit string placement relative to the value string and to set the baseline offset of the unit string --- Pod/Classes/MBCircularProgressBarLayer.h | 11 +++++++++++ Pod/Classes/MBCircularProgressBarLayer.m | 8 ++++++-- Pod/Classes/MBCircularProgressBarView.h | 10 ++++++++++ Pod/Classes/MBCircularProgressBarView.m | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 561a9c1..7d90af3 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -54,6 +54,17 @@ */ @property (nonatomic,copy) NSString *unitString; +/** + * A bool indicating the placement of the unit string relative to the value (YES=right, NO=left) + */ +@property (nonatomic, assign) BOOL unitTrailing; + +/** + * A bool indicating the baseline of the unit string relative to the value (YES=bottom, NO=top) + */ +@property (nonatomic, assign) CGFloat unitBaselineOffset; + + /** * The color of the value and unit text */ diff --git a/Pod/Classes/MBCircularProgressBarLayer.m b/Pod/Classes/MBCircularProgressBarLayer.m index adb4ec5..ddd6cd2 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.m +++ b/Pod/Classes/MBCircularProgressBarLayer.m @@ -33,6 +33,8 @@ @implementation MBCircularProgressBarLayer @dynamic unitFontName; @dynamic valueFontName; @dynamic showUnitString; +@dynamic unitTrailing; +@dynamic unitBaselineOffset; @dynamic showValueString; @dynamic textOffset; @dynamic countdown; @@ -158,11 +160,13 @@ - (void)drawText:(CGSize)rectSize context:(CGContextRef)c // 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: [UIFont fontWithName: self.unitFontName size:self.unitFontSize == -1 ? rectSize.height/7 : self.unitFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle, NSBaselineOffsetAttributeName: [NSNumber numberWithFloat:self.unitBaselineOffset]}; NSAttributedString* unit = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", self.unitString] attributes:unitFontAttributes]; - [text appendAttributedString:unit]; + + // place the unit string before or after the value text + self.unitTrailing ? [text appendAttributedString:unit] : [text insertAttributedString:unit atIndex:0]; } CGSize percentSize = [text size]; diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index 0eb5fab..d7cc594 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -70,6 +70,16 @@ IB_DESIGNABLE */ @property (nonatomic,copy) IBInspectable NSString *unitString; +/** + * A bool indicating the placement of the unit string relative to the value (YES=right, NO=left) + */ +@property (nonatomic, assign) IBInspectable BOOL unitTrailing; + +/** + * A bool indicating the baseline of the unit string relative to the value (YES=bottom, NO=top) + */ +@property (nonatomic, assign) IBInspectable CGFloat unitBaselineOffset; + /** * The color of the value and unit text */ diff --git a/Pod/Classes/MBCircularProgressBarView.m b/Pod/Classes/MBCircularProgressBarView.m index 5c6c71a..289c744 100644 --- a/Pod/Classes/MBCircularProgressBarView.m +++ b/Pod/Classes/MBCircularProgressBarView.m @@ -42,6 +42,8 @@ -(void)initView:(CGRect)frame{ [self setContentScaleFactor:[[UIScreen mainScreen] scale]]; [self setUnitString:@"%"]; + [self setUnitTrailing:YES]; + [self setUnitBaselineOffset:0.f]; [self setValue:0.f]; [self setMaxValue:100.f]; [self setProgressRotationAngle:0.f]; @@ -151,6 +153,22 @@ -(NSString*)unitString{ return self.progressLayer.unitString; } +-(void)setUnitTrailing:(BOOL)unitTrailing { + self.progressLayer.unitTrailing = unitTrailing; +} + +-(BOOL)unitTrailing{ + return self.progressLayer.unitTrailing; +} + +-(void)setUnitBaselineOffset:(CGFloat)unitBaselineOffset { + self.progressLayer.unitBaselineOffset = unitBaselineOffset; +} + +-(CGFloat)unitBaselineOffset{ + return self.progressLayer.unitBaselineOffset; +} + -(void)setFontColor:(UIColor*)color{ self.progressLayer.fontColor = color; } From 11d85facfc9df4f64a63ad764d20c1936c6f0036 Mon Sep 17 00:00:00 2001 From: oriyentel Date: Mon, 14 Nov 2016 18:04:59 -0600 Subject: [PATCH 2/3] updated .h files and readme to include new unit properties --- Pod/Classes/MBCircularProgressBarLayer.h | 2 +- Pod/Classes/MBCircularProgressBarView.h | 2 +- README.md | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 7d90af3..55d5d26 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -60,7 +60,7 @@ @property (nonatomic, assign) BOOL unitTrailing; /** - * A bool indicating the baseline of the unit string relative to the value (YES=bottom, NO=top) + * The offset (in points) of the unit string from the baseline [0,∞) */ @property (nonatomic, assign) CGFloat unitBaselineOffset; diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index d7cc594..6afa596 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -76,7 +76,7 @@ IB_DESIGNABLE @property (nonatomic, assign) IBInspectable BOOL unitTrailing; /** - * A bool indicating the baseline of the unit string relative to the value (YES=bottom, NO=top) + * The offset (in points) of the unit string from the baseline [0,∞) */ @property (nonatomic, assign) IBInspectable CGFloat unitBaselineOffset; diff --git a/README.md b/README.md index bcb1dc0..1104cae 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ 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 unitFontSize | CGFloat | The font size of the unit text | [0,∞) unitString | NSString | The string that represents the units, usually % | +unitTrailing | BOOL | A bool indicating the placement of the unit string relative to the value | {YES=right, NO=left} +unitBaselineOffset | CGFloat | The offset (in points) of the unit string from the baseline | [0,∞) fontColor | UIColor | The color of the value and unit text | decimalPlaces | NSInteger | Number of decimal places of the value | [0,∞) progressRotationAngle | CGFloat | Progress bar rotation (Clockewise)| [0,100] From 46e2ef08202ae0f35a0eccc37503ccd635fc0bf2 Mon Sep 17 00:00:00 2001 From: oriyentel Date: Mon, 14 Nov 2016 18:27:47 -0600 Subject: [PATCH 3/3] updated h files to correctly define the range of unitBaselineOffset --- Pod/Classes/MBCircularProgressBarLayer.h | 2 +- Pod/Classes/MBCircularProgressBarView.h | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 55d5d26..ea5c128 100644 --- a/Pod/Classes/MBCircularProgressBarLayer.h +++ b/Pod/Classes/MBCircularProgressBarLayer.h @@ -60,7 +60,7 @@ @property (nonatomic, assign) BOOL unitTrailing; /** - * The offset (in points) of the unit string from the baseline [0,∞) + * The offset (in points) of the unit string from the baseline (∞,∞) */ @property (nonatomic, assign) CGFloat unitBaselineOffset; diff --git a/Pod/Classes/MBCircularProgressBarView.h b/Pod/Classes/MBCircularProgressBarView.h index 6afa596..4441ea7 100644 --- a/Pod/Classes/MBCircularProgressBarView.h +++ b/Pod/Classes/MBCircularProgressBarView.h @@ -76,7 +76,7 @@ IB_DESIGNABLE @property (nonatomic, assign) IBInspectable BOOL unitTrailing; /** - * The offset (in points) of the unit string from the baseline [0,∞) + * The offset (in points) of the unit string from the baseline (∞,∞) */ @property (nonatomic, assign) IBInspectable CGFloat unitBaselineOffset; diff --git a/README.md b/README.md index 1104cae..adc33f9 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ valueFontName | NSString | The name of the font of the unit string | Any valid f unitFontSize | CGFloat | The font size of the unit text | [0,∞) unitString | NSString | The string that represents the units, usually % | unitTrailing | BOOL | A bool indicating the placement of the unit string relative to the value | {YES=right, NO=left} -unitBaselineOffset | CGFloat | The offset (in points) of the unit string from the baseline | [0,∞) +unitBaselineOffset | CGFloat | The offset (in points) of the unit string from the baseline | (∞,∞) fontColor | UIColor | The color of the value and unit text | decimalPlaces | NSInteger | Number of decimal places of the value | [0,∞) progressRotationAngle | CGFloat | Progress bar rotation (Clockewise)| [0,100]