Skip to content

Instantly share code, notes, and snippets.

@cyndibaby905
Created December 17, 2013 11:00
Show Gist options
  • Save cyndibaby905/8003205 to your computer and use it in GitHub Desktop.
Save cyndibaby905/8003205 to your computer and use it in GitHub Desktop.
Draw circle with two colors
CGFloat borderWidth = 3.f;
CGFloat circleRadius = self.bounds.size.width / 2 - borderWidth;
CGPoint circleCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:255.0/255.0 green:210.0/255.0 blue:60.0/255.0 alpha:1] CGColor]);
UIBezierPath *firstHalf = [UIBezierPath bezierPath];
[firstHalf addArcWithCenter:circleCenter radius:circleRadius startAngle:-M_PI_2 endAngle:M_PI_2 clockwise:YES];
[firstHalf setLineWidth:borderWidth];
[firstHalf stroke];
CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:255.0/255.0 green:109.0/255.0 blue:38.0/255.0 alpha:1] CGColor]);
UIBezierPath *secondHalf = [UIBezierPath bezierPath];
[secondHalf addArcWithCenter:circleCenter radius:circleRadius startAngle:M_PI_2 endAngle:3.0 * M_PI_2 clockwise:YES];
[secondHalf setLineWidth:borderWidth];
[secondHalf stroke];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment