Created
July 10, 2014 09:14
-
-
Save kazukitanaka0611/d30d235c37a6a8368895 to your computer and use it in GitHub Desktop.
drawRect radias view
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 | |
{ | |
// Drawing code | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGMutablePathRef path = createRoundeRectForRect(self.bounds, 15.0); | |
CGContextSaveGState(context); | |
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); | |
CGContextAddPath(context, path); | |
CGContextFillPath(context); | |
CGContextRestoreGState(context); | |
CGContextRelease(context); | |
} | |
#pragma mark - private method | |
CGMutablePathRef createRoundeRectForRect(CGRect rect, CGFloat radius) | |
{ | |
CGMutablePathRef path = CGPathCreateMutable(); | |
CGPathMoveToPoint(path, NULL, CGRectGetMidX(rect), CGRectGetMinY(rect)); | |
CGPathAddArcToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMinY(rect), | |
CGRectGetMaxX(rect), CGRectGetMaxY(rect), radius); | |
CGPathAddArcToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMaxY(rect), | |
CGRectGetMinX(rect), CGRectGetMaxY(rect), radius); | |
CGPathAddArcToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMaxY(rect), | |
CGRectGetMinX(rect), CGRectGetMinY(rect), radius); | |
CGPathAddArcToPoint(path, NULL, CGRectGetMinX(rect), CGRectGetMinY(rect), | |
CGRectGetMaxX(rect), CGRectGetMinY(rect), radius); | |
CGPathCloseSubpath(path); | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment