Last active
December 22, 2015 07:19
-
-
Save rcdilorenzo/6437406 to your computer and use it in GitHub Desktop.
CoreGraphics - clipping an inner circle (used in reference to a Stack Overflow question: http://stackoverflow.com/questions/18614376/calayer-clip-cgcontextaddarc-making-a-donut-slide-pie-chart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)drawRect:(CGRect)rect { | |
UIBezierPath *path = [UIBezierPath bezierPath]; | |
[path addArcWithCenter:CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)) radius:CGRectGetHeight(self.bounds) startAngle:0 endAngle:2.0*M_PI clockwise:YES]; | |
[path addArcWithCenter:CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)) radius:100 startAngle:0 endAngle:2.0*M_PI clockwise:NO]; | |
[path addClip]; | |
self.layer.cornerRadius = 10.0; | |
CGFloat colors[12] = { | |
0.1, 0.18, 0.54, 1.0, | |
0.38, 0.44, 0.65, 1.0, | |
0.1, 0.18, 0.54, 1.0 | |
}; | |
CGFloat colorStops[3] = {0.0, 0.5, 1.0}; | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, | |
colors, | |
colorStops, | |
3); | |
CGColorSpaceRelease(colorSpace); | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
CGContextDrawRadialGradient(ctx, gradient, CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)), 100, CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)), CGRectGetHeight(self.bounds)/2, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment