标签:
可以利用 CGMutablePathRef 创建每个不同图形,然后再一起添加到CGContext中
- (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); //一、 画线 // 1.先创建一个路径 CGMutablePathRef linePath = CGPathCreateMutable(); // 2.拼接路径 CGPathMoveToPoint(linePath, nil, 0, 0); CGPathAddLineToPoint(linePath, nil, 100, 100); // 添加路径到上下文 CGContextAddPath(ctx, linePath); //二、 画圆 CGMutablePathRef circlePath = CGPathCreateMutable(); CGPathAddEllipseInRect(circlePath, nil, CGRectMake(150, 150, 100, 100)); CGContextAddPath(ctx, circlePath); // 渲染 CGContextStrokePath(ctx); // Creat\Copy\retain 用过之后都要做一次release CGPathRelease(linePath); CGPathRelease(circlePath); }
利用Quartz2D推图的另一个方法 (使用CGMutalePathRef进行分层次)
标签:
原文地址:http://www.cnblogs.com/cjt5132/p/4616932.html