Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created January 29, 2009 16:47
Show Gist options
  • Select an option

  • Save KirinDave/54616 to your computer and use it in GitHub Desktop.

Select an option

Save KirinDave/54616 to your computer and use it in GitHub Desktop.
- (void)drawRect:(CGRect)rect {
[[UIColor grayColor] setFill];
UIRectFill(rect);
[[UIColor blueColor] setFill];
CGRect drawnRect = CGRectInset(rect, 20.0f, 20.0f);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, drawnRect);
CGRect elipseRect = CGRectInset(drawnRect, 25.0f, 25.0f);
CGPathAddEllipseInRect(path, NULL, elipseRect);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, path);
CGContextEOFillPath(ctx);
// Triangle
path = CGPathCreateMutable();
float baseX = rect.size.width / 2.0f;
float baseY = rect.size.height / 2.0f;
float offX = 100.0f;
float offY = 50.0f;
NSLog(@"%f %f", baseX, baseY);
CGPathMoveToPoint(path, NULL, baseX + offX, baseY + offY);
CGPathAddLineToPoint(path, NULL, baseX - offX, baseY + offY );
CGPathAddLineToPoint(path, NULL, baseX, baseY - offY);
CGPathAddLineToPoint(path, NULL, baseX + offX, baseY + offY);
[[UIColor redColor] setFill];
CGContextAddPath(ctx, path);
CGContextFillPath(ctx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment