Created
September 14, 2012 01:40
-
-
Save taberh/3719302 to your computer and use it in GitHub Desktop.
Use Core Graphics draw corner
This file contains 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 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