Created
May 15, 2011 21:11
-
-
Save aaronbrethorst/973544 to your computer and use it in GitHub Desktop.
This file contains hidden or 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)drawRect:(CGRect)rect { | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGFloat minx = CGRectGetMinX(rect); | |
CGFloat midx = CGRectGetMidX(rect); | |
CGFloat maxx = CGRectGetMaxX(rect); | |
CGFloat miny = CGRectGetMinY(rect); | |
CGFloat midy = CGRectGetMidY(rect); | |
CGFloat maxy = CGRectGetMaxY(rect); | |
CGContextMoveToPoint(context, minx, midy); | |
if (self.squareCorners) { | |
CGContextAddLineToPoint(context, minx, miny); // move to bottom-left | |
CGContextAddLineToPoint(context, midx, miny); // move to botttom-mid | |
CGContextAddArcToPoint(context, maxx, miny, maxx, midy, kCornerRadius); // add an arc in the bottom right corner | |
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, kCornerRadius); // add an arc in the top right corner | |
CGContextAddLineToPoint(context, minx, maxy); // move to top-left | |
} else { | |
CGContextAddArcToPoint(context, minx, miny, midx, miny, kCornerRadius); | |
CGContextAddArcToPoint(context, maxx, miny, maxx, midy, kCornerRadius); | |
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, kCornerRadius); | |
CGContextAddArcToPoint(context, minx, maxy, minx, midy, kCornerRadius); | |
} | |
CGContextClosePath(context); | |
CGContextFillPath(context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment