diff --git a/Pod/Classes/MBCircularProgressBarLayer.h b/Pod/Classes/MBCircularProgressBarLayer.h index 561a9c1..ea5c128 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; + +/** + * The offset (in points) of the unit string from the baseline (∞,∞) + */ +@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..4441ea7 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; + +/** + * The offset (in points) of the unit string from the baseline (∞,∞) + */ +@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; } diff --git a/README.md b/README.md index bcb1dc0..adc33f9 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 | (∞,∞) 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]