diff --git a/SSToolkit/SSPieProgressView.h b/SSToolkit/SSPieProgressView.h index 1db664f..8cf9a5b 100644 --- a/SSToolkit/SSPieProgressView.h +++ b/SSToolkit/SSPieProgressView.h @@ -37,12 +37,26 @@ @property (nonatomic, assign) CGFloat pieBorderWidth; /** - The border color. + The outer border color. @see defaultPieColor */ @property (nonatomic, strong) UIColor *pieBorderColor; +/** + The inner border width. + + The default is `2.0`. + */ +@property (nonatomic, assign) CGFloat pieInnerBorderWidth; + +/** + The inner border color. + + @see defaultPieColor + */ +@property (nonatomic, strong) UIColor *pieInnerBorderColor; + /** The fill color. diff --git a/SSToolkit/SSPieProgressView.m b/SSToolkit/SSPieProgressView.m index 8a39a48..1ad8eec 100644 --- a/SSToolkit/SSPieProgressView.m +++ b/SSToolkit/SSPieProgressView.m @@ -22,6 +22,8 @@ @implementation SSPieProgressView @synthesize progress = _progress; @synthesize pieBorderWidth = _pieBorderWidth; @synthesize pieBorderColor = _pieBorderColor; +@synthesize pieInnerBorderWidth = _pieInnerBorderWidth; +@synthesize pieInnerBorderColor = _pieInnerBorderColor; @synthesize pieFillColor = _pieFillColor; @synthesize pieBackgroundColor = _pieBackgroundColor; @@ -42,6 +44,19 @@ - (void)setPieBorderColor:(UIColor *)pieBorderColor { [self setNeedsDisplay]; } + +- (void)setPieInnerBorderWidth:(CGFloat)pieInnerBorderWidth { + _pieInnerBorderWidth = pieInnerBorderWidth; + [self setNeedsDisplay]; +} + + +- (void)setPieInnerBorderColor:(UIColor *)pieInnerBorderColor { + _pieInnerBorderColor = pieInnerBorderColor; + [self setNeedsDisplay]; +} + + - (void)setPieFillColor:(UIColor *)pieFillColor { _pieFillColor = pieFillColor; [self setNeedsDisplay]; @@ -81,33 +96,41 @@ - (id)initWithFrame:(CGRect)aFrame { - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextClipToRect(context, rect); // Background if (_pieBackgroundColor) { [_pieBackgroundColor set]; CGContextFillEllipseInRect(context, rect); } - + + // Math + CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); + CGFloat radius = center.y; + CGFloat angle = DEGREES_TO_RADIANS((360.0f * _progress) + kAngleOffset); + CGPoint points[3] = { + CGPointMake(center.x, 0.0f), + center, + CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle)) + }; + // Fill if (_pieFillColor) { [_pieFillColor set]; if (_progress > 0.0f) { - CGPoint center = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); - CGFloat radius = center.y; - CGFloat angle = DEGREES_TO_RADIANS((360.0f * _progress) + kAngleOffset); - CGPoint points[3] = { - CGPointMake(center.x, 0.0f), - center, - CGPointMake(center.x + radius * cosf(angle), center.y + radius * sinf(angle)) - }; CGContextAddLines(context, points, sizeof(points) / sizeof(points[0])); CGContextAddArc(context, center.x, center.y, radius, DEGREES_TO_RADIANS(kAngleOffset), angle, false); CGContextDrawPath(context, kCGPathEOFill); } } - - // Border + + // Inner Border + if (_progress < 0.99f && _pieInnerBorderColor && _pieInnerBorderWidth > 0.0f) { + [_pieInnerBorderColor set]; + CGContextAddLines(context, points, sizeof(points) / sizeof(points[0])); + CGContextDrawPath(context, kCGPathStroke); + } + + // Outer Border if (_pieBorderColor && _pieBorderWidth > 0.0f) { [_pieBorderColor set]; CGContextSetLineWidth(context, _pieBorderWidth);