Skip to content

Instantly share code, notes, and snippets.

@taberh
Created September 14, 2012 01:40
Show Gist options
  • Save taberh/3719302 to your computer and use it in GitHub Desktop.
Save taberh/3719302 to your computer and use it in GitHub Desktop.
Use Core Graphics draw corner
void drawCorner(CGContextRef context, CGRect rect, float corner)
{
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM(context, corner, corner);
CGFloat fw = CGRectGetWidth(rect) / corner;
CGFloat fh = CGRectGetHeight(rect) / corner;
CGContextMoveToPoint(context, fw, fh/2);
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1);
CGContextClosePath(context);
CGContextFillPath(context);
CGContextRestoreGState(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment