- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, CGRectMake(100, 100, 50, 50));
CGContextClip(ctx);
CGContextStrokePath(ctx);
UIImage *image = [UIImage imageNamed:@"me"];
[image drawAtPoint:CGPointMake(100, 100)];
CGContextFillPath(ctx);
}
- (void)drawRect:(CGRect)rect
{
// 画四边形
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGContextRotateCTM(ctx, M_PI_4);
CGContextAddRect(ctx, CGRectMake(200, 100, 100, 100));
CGContextRestoreGState(ctx);
CGContextAddEllipseInRect(ctx, CGRectMake(20, 20, 100, 100));
CGContextStrokePath(ctx);
}