Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add pieInnerBorderColor and pieInnerBorderWidth to SSPieProgressView

  • Loading branch information...
commit 42ead55a6bca3ea2dfe4e7dc565c93a24ced584a 1 parent 27e5691
@soffes soffes authored
Showing with 50 additions and 13 deletions.
  1. +15 −1 SSToolkit/SSPieProgressView.h
  2. +35 −12 SSToolkit/SSPieProgressView.m
View
16 SSToolkit/SSPieProgressView.h
@@ -37,13 +37,27 @@
@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.
@see defaultPieColor
View
47 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);
Please sign in to comment.
Something went wrong with that request. Please try again.