Skip to content
Browse files

Prevent drawing things that are undefined in SSPieProgressView

  • Loading branch information...
1 parent 6ff11e7 commit 27e5691101de090d6f00d84e9b33847b304b5792 @soffes soffes committed Oct 19, 2012
Showing with 25 additions and 19 deletions.
  1. +25 −19 SSToolkit/SSPieProgressView.m
View
44 SSToolkit/SSPieProgressView.m
@@ -84,30 +84,36 @@ - (void)drawRect:(CGRect)rect {
CGContextClipToRect(context, rect);
// Background
- [_pieBackgroundColor set];
- CGContextFillEllipseInRect(context, rect);
+ if (_pieBackgroundColor) {
+ [_pieBackgroundColor set];
+ CGContextFillEllipseInRect(context, rect);
+ }
// Fill
- [_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);
+ 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
- [_pieBorderColor set];
- CGContextSetLineWidth(context, _pieBorderWidth);
- CGRect pieInnerRect = CGRectMake(_pieBorderWidth / 2.0f, _pieBorderWidth / 2.0f, rect.size.width - _pieBorderWidth, rect.size.height - _pieBorderWidth);
- CGContextStrokeEllipseInRect(context, pieInnerRect);
+ if (_pieBorderColor && _pieBorderWidth > 0.0f) {
+ [_pieBorderColor set];
+ CGContextSetLineWidth(context, _pieBorderWidth);
+ CGRect pieInnerRect = CGRectMake(_pieBorderWidth / 2.0f, _pieBorderWidth / 2.0f, rect.size.width - _pieBorderWidth, rect.size.height - _pieBorderWidth);
+ CGContextStrokeEllipseInRect(context, pieInnerRect);
+ }
}

0 comments on commit 27e5691

Please sign in to comment.
Something went wrong with that request. Please try again.