Skip to content

Commit

Permalink
Add pieInnerBorderColor and pieInnerBorderWidth to SSPieProgressView
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Oct 19, 2012
1 parent 27e5691 commit 42ead55
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
16 changes: 15 additions & 1 deletion SSToolkit/SSPieProgressView.h
Expand Up @@ -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.
Expand Down
47 changes: 35 additions & 12 deletions SSToolkit/SSPieProgressView.m
Expand Up @@ -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;

Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 42ead55

Please sign in to comment.