Skip to content

Instantly share code, notes, and snippets.

@HeidiHansen
Last active August 29, 2015 14:06
Show Gist options
  • Save HeidiHansen/ac170dfa3d6a0e2b5a02 to your computer and use it in GitHub Desktop.
Save HeidiHansen/ac170dfa3d6a0e2b5a02 to your computer and use it in GitHub Desktop.
THCameraButton.m drawRect method. Custom drawn camera button, iOS 7 default camera button look-alike.
#define DegreesToRadians(x) ((x) * M_PI / 180.0)
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGFloat buttonRadius = rect.size.width/2;
CGFloat buttonRing = buttonRadius - (buttonRadius/5.5);
CGFloat buttonFill = buttonRing - (buttonRadius/12);
CGPathAddArc(path, NULL, buttonRadius, buttonRadius, buttonRadius - 2, DegreesToRadians(0), DegreesToRadians(360), 0);
CGPathMoveToPoint(path, NULL, buttonRadius, buttonRadius);
CGPathAddArc(path, NULL, buttonRadius, buttonRadius, buttonRing, DegreesToRadians(0), DegreesToRadians(360), 0);
CGPathMoveToPoint(path, NULL, buttonRadius, buttonRadius);
CGPathAddArc(path, NULL, buttonRadius, buttonRadius, buttonFill, DegreesToRadians(0), DegreesToRadians(360), 0);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextAddPath(context, path);
CGContextEOFillPath(context);
CGPathRelease(path);
UIGraphicsEndImageContext();
}
@HeidiHansen
Copy link
Author

Draws a resizable button identical to the iOS7 Default Camera Button using EOFillPath CGContext method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment