Skip to content

Instantly share code, notes, and snippets.

@kazukitanaka0611
Created July 10, 2014 09:14
Show Gist options
  • Save kazukitanaka0611/d30d235c37a6a8368895 to your computer and use it in GitHub Desktop.
Save kazukitanaka0611/d30d235c37a6a8368895 to your computer and use it in GitHub Desktop.
drawRect radias view
- (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