Skip to content

Instantly share code, notes, and snippets.

@mweyamutsvene
Created October 2, 2012 18:22
Show Gist options
  • Save mweyamutsvene/3822032 to your computer and use it in GitHub Desktop.
Save mweyamutsvene/3822032 to your computer and use it in GitHub Desktop.
//Draw the shadow for center component
CGContextSetFillColorWithColor( ctx, [UIColor colorWithWhite:.1 alpha:.4].CGColor );
CGContextFillEllipseInRect( ctx, CGRectInset(self.bounds, CENTER_INSET-4, CENTER_INSET-4) );
//Draw center transparent mask
CGContextSetFillColorWithColor( ctx, [UIColor clearColor].CGColor );
CGContextSetBlendMode(ctx, kCGBlendModeClear);
CGContextFillEllipseInRect( ctx, CGRectInset(self.bounds, CENTER_INSET, CENTER_INSET) );
// Get the graphics context and clear it
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
// define stroke color
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1.0);
// define line width
CGContextSetLineWidth(ctx, 4.0);
//Create fill gradient
CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, gradientColor, locations, 3);
CGColorSpaceRelease(baseSpace), baseSpace = NULL;
CGContextSaveGState(ctx);
CGContextAddEllipseInRect(ctx, CGRectInset(rect, 0, 0));
CGContextClip(ctx);
CGPoint centerpoint = CGPointMake(rect.origin.x + (rect.size.width / 2), rect.origin.y + (rect.size.height / 2));
CGContextDrawRadialGradient(ctx, gradient, centerpoint, 0, centerpoint, rect.size.height*.5, 0);
CGGradientRelease(gradient), gradient = NULL;
CGContextRestoreGState(ctx);
// draw pie chart
CGContextSetFillColorWithColor( ctx, _trackColor.CGColor );
CGContextSetStrokeColorWithColor(ctx, _trackColor.CGColor);
CGContextMoveToPoint(ctx, x, y);
CGContextAddArc(ctx, x, y, x, radians(start), radians(finish), 1);
CGContextFillPath(ctx);
CGContextStrokePath(ctx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment