Created
August 26, 2012 23:47
-
-
Save nielsbot/3484435 to your computer and use it in GitHub Desktop.
Function to create a round rect CGPath
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
CGPathRef CGPathCreateRoundRect( const CGRect r, const CGFloat cornerRadius ) | |
{ | |
CGMutablePathRef p = CGPathCreateMutable() ; | |
CGPathMoveToPoint( p, NULL, r.origin.x + cornerRadius, r.origin.y ) ; | |
CGFloat maxX = CGRectGetMaxX( r ) ; | |
CGFloat maxY = CGRectGetMaxY( r ) ; | |
CGPathAddArcToPoint( p, NULL, maxX, r.origin.y, maxX, r.origin.y + cornerRadius, cornerRadius ) ; | |
CGPathAddArcToPoint( p, NULL, maxX, maxY, maxX - cornerRadius, maxY, cornerRadius ) ; | |
CGPathAddArcToPoint( p, NULL, r.origin.x, maxY, r.origin.x, maxY - cornerRadius, cornerRadius ) ; | |
CGPathAddArcToPoint( p, NULL, r.origin.x, r.origin.y, r.origin.x + cornerRadius, r.origin.y, cornerRadius ) ; | |
return p ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift code: