Skip to content

Instantly share code, notes, and snippets.

@augustjoki
Created October 16, 2008 23:08
Show Gist options
  • Save augustjoki/17289 to your computer and use it in GitHub Desktop.
Save augustjoki/17289 to your computer and use it in GitHub Desktop.
CGSize size = CGSizeMake(90.0, 90.0);
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat radius = 5.0;
CGFloat minx = CGRectGetMinX(rect), midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect);
CGFloat miny = CGRectGetMinY(rect), midy = CGRectGetMidY(rect), maxy = CGRectGetMaxY(rect);
// Rounded rect path
CGMutablePathRef path = CGPathCreateMutable();
// start at mid left
CGPathMoveToPoint(path, NULL, minx, midy);
// add upper left arc
CGPathAddArcToPoint(path, NULL, minx, miny, midx, miny, radius);
// add upper right arc
CGPathAddArcToPoint(path, NULL, maxx, miny, maxx, midy, radius);
// add lower right arc - Comment to create TearDrop Shape
CGPathAddArcToPoint(path, NULL, maxx, maxy, midx, maxy, radius);
// add lower left arc
CGPathAddArcToPoint(path, NULL, minx, maxy, minx, midy, radius);
// close path
CGPathCloseSubpath(path);
// add path to context
CGContextAddPath(context, path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment