Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions Pod/Classes/MBCircularProgressBarLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,121 +17,121 @@
/**
* Set a partial angle for the progress bar [0,100]
*/
@property (nonatomic,assign) CGFloat progressAngle;
@property (nonatomic,assign) CGFloat progressAngle;

/**
* Progress bar rotation (Clockewise) [0,100]
*/
@property (nonatomic,assign) CGFloat progressRotationAngle;
@property (nonatomic,assign) CGFloat progressRotationAngle;

/**
* The value of the progress bar
*/
@property (nonatomic,assign) CGFloat value;
@property (nonatomic,assign) CGFloat value;

/**
* The maximum possible value, used to calculate the progress (value/maxValue) [0,∞)
*/
@property (nonatomic,assign) CGFloat maxValue;
@property (nonatomic,assign) CGFloat maxValue;

/**
* Animation duration in seconds
*/
@property (nonatomic,assign) NSTimeInterval animationDuration;
@property (nonatomic,assign) NSTimeInterval animationDuration;

/**
* Defines if the progress should animate on value change
*/
@property (nonatomic,assign) BOOL animated;
@property (nonatomic,assign) BOOL animated;

/**
* The font size of the value text [0,∞)
*/
@property (nonatomic,assign) CGFloat valueFontSize;
@property (nonatomic,assign) CGFloat valueFontSize;

/**
* The name of the font of the unit string
*/
@property (nonatomic,assign) CGFloat unitFontSize;
@property (nonatomic,assign) CGFloat unitFontSize;

/**
* The string that represents the units, usually %
*/
@property (nonatomic,copy) NSString *unitString;
@property (nonatomic,copy,nullable) NSString *unitString;

/**
* The color of the value and unit text
*/
@property (nonatomic,strong) UIColor *fontColor;
@property (nonatomic,strong,nullable) UIColor *fontColor;

/**
* The width of the progress bar (user space units) [0,∞)
*/
@property (nonatomic,assign) CGFloat progressLineWidth;
@property (nonatomic,assign) CGFloat progressLineWidth;

/**
* The color of the progress bar
*/
@property (nonatomic,strong) UIColor *progressColor;
@property (nonatomic,strong,nullable) UIColor *progressColor;

/**
* The color of the progress bar frame
*/
@property (nonatomic,strong) UIColor *progressStrokeColor;
@property (nonatomic,strong,nullable) UIColor *progressStrokeColor;

/**
* The shape of the progress bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
*/
@property (nonatomic,assign) CGLineCap progressCapType;
@property (nonatomic,assign) CGLineCap progressCapType;

/**
* The width of the background bar (user space units) [0,∞)
*/
@property (nonatomic,assign) CGFloat emptyLineWidth;
@property (nonatomic,assign) CGFloat emptyLineWidth;

/**
* The shape of the background bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
*/
@property (nonatomic,assign) CGLineCap emptyCapType;
@property (nonatomic,assign) CGLineCap emptyCapType;

/**
* The color of the background bar
*/
@property (nonatomic,strong) UIColor *emptyLineColor;
@property (nonatomic,strong,nullable) UIColor *emptyLineColor;

/*
* Number of decimal places of the value [0,∞)
*/
@property (nonatomic,assign) NSInteger decimalPlaces;
@property (nonatomic,assign) NSInteger decimalPlaces;

/**
* The value to be displayed in the center
*/
@property (nonatomic,assign) CGFloat valueDecimalFontSize;
@property (nonatomic,assign) CGFloat valueDecimalFontSize;

/**
* The font size of the unit text [0,∞)
*/
@property (nonatomic,copy) NSString *unitFontName;
@property (nonatomic,copy,nullable) NSString *unitFontName;

/**
* The name of the font of the unit string
*/
@property (nonatomic,copy) NSString *valueFontName;
@property (nonatomic,copy,nullable) NSString *valueFontName;

/**
* Should show unit screen
*/
@property (nonatomic,assign) BOOL showUnitString;
@property (nonatomic,assign) BOOL showUnitString;

/**
* The offset to apply to the unit / value text
*/
@property (nonatomic,assign) CGPoint textOffset;
@property (nonatomic,assign) CGPoint textOffset;

/**
* Should show value string
*/
@property (nonatomic,assign) BOOL showValueString;
@property (nonatomic,assign) BOOL showValueString;

@end
72 changes: 62 additions & 10 deletions Pod/Classes/MBCircularProgressBarLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ - (void)drawEmptyBar:(CGSize)rectSize context:(CGContextRef)c{


CGContextAddPath(c, strokedArc);
CGContextSetStrokeColorWithColor(c, self.emptyLineColor.CGColor);
CGContextSetFillColorWithColor(c, self.emptyLineColor.CGColor);

CGColorRef emptyLineColor;
if (self.emptyLineColor) {
emptyLineColor = self.emptyLineColor.CGColor;
} else {
emptyLineColor = [UIColor lightGrayColor].CGColor;
}

CGContextSetStrokeColorWithColor(c, emptyLineColor);
CGContextSetFillColorWithColor(c, emptyLineColor);
CGContextDrawPath(c, kCGPathFillStroke);

CGPathRelease(arc);
Expand Down Expand Up @@ -109,8 +117,23 @@ - (void)drawProgressBar:(CGSize)rectSize context:(CGContextRef)c{


CGContextAddPath(c, strokedArc);
CGContextSetFillColorWithColor(c, self.progressColor.CGColor);
CGContextSetStrokeColorWithColor(c, self.progressStrokeColor.CGColor);

CGColorRef progressColor;
if (self.progressColor) {
progressColor = self.progressColor.CGColor;
} else {
progressColor = [UIColor orangeColor].CGColor;
}
CGContextSetFillColorWithColor(c, progressColor);

CGColorRef progressStrokeColor;
if (self.progressStrokeColor) {
progressStrokeColor = self.progressStrokeColor.CGColor;
} else {
progressStrokeColor = [UIColor orangeColor].CGColor;
}
CGContextSetStrokeColorWithColor(c, progressStrokeColor);

CGContextDrawPath(c, kCGPathFillStroke);

CGPathRelease(arc);
Expand All @@ -124,9 +147,21 @@ - (void)drawText:(CGSize)rectSize context:(CGContextRef)c
NSMutableParagraphStyle* textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
textStyle.alignment = NSTextAlignmentLeft;

CGFloat valueFontSize = self.valueFontSize == -1 ? rectSize.height/5 : self.valueFontSize;
CGFloat valueFontSize = self.valueFontSize < 0 ? rectSize.height/5 : self.valueFontSize;

NSDictionary* valueFontAttributes = @{NSFontAttributeName: [UIFont fontWithName: self.valueFontName size:valueFontSize], NSForegroundColorAttributeName: self.fontColor, NSParagraphStyleAttributeName: textStyle};
UIFont* valueFont = [UIFont fontWithName:self.valueFontName size:valueFontSize];
if (!valueFont) {
valueFont = [UIFont systemFontOfSize:valueFontSize];
}

UIColor* fontColor;
if (self.fontColor) {
fontColor = self.fontColor;
} else {
fontColor = [UIColor blackColor];
}

NSDictionary* valueFontAttributes = @{NSFontAttributeName: valueFont, NSForegroundColorAttributeName: fontColor, NSParagraphStyleAttributeName: textStyle};

NSMutableAttributedString *text = [NSMutableAttributedString new];

Expand All @@ -140,17 +175,34 @@ - (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};
UIFont* valueDecimalFont = [UIFont fontWithName:self.valueFontName size:self.valueDecimalFontSize < 0 ? valueFontSize : self.valueDecimalFontSize];
if (!valueDecimalFont) {
valueDecimalFont = [UIFont systemFontOfSize:valueFontSize];
}

NSDictionary* valueDecimalFontAttributes = @{NSFontAttributeName: valueDecimalFont, NSForegroundColorAttributeName: 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};

UIFont* unitFont = [UIFont fontWithName:self.unitFontName size:self.unitFontSize < 0 ? rectSize.height/7 : self.unitFontSize];
if (!unitFont) {
unitFont = [UIFont systemFontOfSize:valueFontSize];
}

NSDictionary* unitFontAttributes = @{NSFontAttributeName: unitFont, NSForegroundColorAttributeName: fontColor, NSParagraphStyleAttributeName: textStyle};

NSString* unitString;
if (self.unitString) {
unitString = [NSString stringWithFormat:@"%@", self.unitString];
} else {
unitString = @"%";
}

NSAttributedString* unit =
[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", self.unitString] attributes:unitFontAttributes];
[[NSAttributedString alloc] initWithString:unitString attributes:unitFontAttributes];
[text appendAttributedString:unit];
}

Expand Down
52 changes: 26 additions & 26 deletions Pod/Classes/MBCircularProgressBarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,112 +18,112 @@ IB_DESIGNABLE
/**
* Should show value string
*/
@property (nonatomic,assign) IBInspectable BOOL showValueString;
@property (nonatomic,assign) IBInspectable BOOL showValueString;

/**
* The value of the progress bar
*/
@property (nonatomic,assign) IBInspectable CGFloat value;
@property (nonatomic,assign) IBInspectable CGFloat value;

/**
* The maximum possible value, used to calculate the progress (value/maxValue) [0,∞)
* The maximum possible value, used to calculate the progress (value/maxValue) [0,∞)
*/
@property (nonatomic,assign) IBInspectable CGFloat maxValue;
@property (nonatomic,assign) IBInspectable CGFloat maxValue;

/*
* Number of decimal places of the value [0,∞)
*/
@property (nonatomic,assign) IBInspectable NSInteger decimalPlaces;
@property (nonatomic,assign) IBInspectable NSInteger decimalPlaces;

/**
* The name of the font of the value string
*/
@property (nonatomic,copy) IBInspectable NSString *valueFontName;
@property (nonatomic,copy,nullable) IBInspectable NSString *valueFontName;

/**
* The font size of the value text [0,∞)
*/
@property (nonatomic,assign) IBInspectable CGFloat valueFontSize;
@property (nonatomic,assign) IBInspectable CGFloat valueFontSize;

/**
* The value to be displayed in the center
*/
@property (nonatomic,assign) IBInspectable CGFloat valueDecimalFontSize;
@property (nonatomic,assign) IBInspectable CGFloat valueDecimalFontSize;

/**
* Should show unit screen
*/
@property (nonatomic,assign) IBInspectable BOOL showUnitString;
@property (nonatomic,assign) IBInspectable BOOL showUnitString;

/**
* The name of the font of the unit string
*/
@property (nonatomic,copy) IBInspectable NSString *unitFontName;
@property (nonatomic,copy,nullable) IBInspectable NSString *unitFontName;

/**
* The font size of the unit text [0,∞)
* The font size of the unit text [0,∞)
*/
@property (nonatomic,assign) IBInspectable CGFloat unitFontSize;
@property (nonatomic,assign) IBInspectable CGFloat unitFontSize;

/**
* The string that represents the units, usually %
*/
@property (nonatomic,copy) IBInspectable NSString *unitString;
@property (nonatomic,copy,nullable) IBInspectable NSString *unitString;

/**
* The color of the value and unit text
*/
@property (nonatomic,strong) IBInspectable UIColor *fontColor;
@property (nonatomic,strong,nullable) IBInspectable UIColor *fontColor;

/**
* Progress bar rotation (Clockewise) [0,100]
*/
@property (nonatomic,assign) IBInspectable CGFloat progressRotationAngle;
@property (nonatomic,assign) IBInspectable CGFloat progressRotationAngle;

/**
* Set a partial angle for the progress bar [0,100]
*/
@property (nonatomic,assign) IBInspectable CGFloat progressAngle;
@property (nonatomic,assign) IBInspectable CGFloat progressAngle;

/**
* The width of the progress bar (user space units) [0,∞)
*/
@property (nonatomic,assign) IBInspectable CGFloat progressLineWidth;
@property (nonatomic,assign) IBInspectable CGFloat progressLineWidth;

/**
* The color of the progress bar
*/
@property (nonatomic,strong) IBInspectable UIColor *progressColor;
@property (nonatomic,strong,nullable) IBInspectable UIColor *progressColor;

/**
* The color of the progress bar frame
*/
@property (nonatomic,strong) IBInspectable UIColor *progressStrokeColor;
@property (nonatomic,strong,nullable) IBInspectable UIColor *progressStrokeColor;

/**
* The shape of the progress bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
* The shape of the progress bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
*/
@property (nonatomic,assign) IBInspectable NSInteger progressCapType;
@property (nonatomic,assign) IBInspectable NSInteger progressCapType;

/**
* The width of the background bar (user space units) [0,∞)
*/
@property (nonatomic,assign) IBInspectable CGFloat emptyLineWidth;
@property (nonatomic,assign) IBInspectable CGFloat emptyLineWidth;

/**
* The color of the background bar
*/
@property (nonatomic,strong) IBInspectable UIColor *emptyLineColor;
@property (nonatomic,strong,nullable) IBInspectable UIColor *emptyLineColor;

/**
* The shape of the background bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
* The shape of the background bar cap {kCGLineCapButt=0, kCGLineCapRound=1, kCGLineCapSquare=2}
*/
@property (nonatomic,assign) IBInspectable NSInteger emptyCapType;
@property (nonatomic,assign) IBInspectable NSInteger emptyCapType;

/**
* The offset to apply to the unit / value text
*/
@property (nonatomic,assign) IBInspectable CGPoint textOffset;
@property (nonatomic,assign) IBInspectable CGPoint textOffset;

/**
* Set the value of the progress bar with animation
Expand Down
Loading