①创建路径:
CGMutablePathRef pathLine = CGPathCreateMutable();
②在路径上绘制图形:
CGPathMoveToPoint(pathLine, NULL, 0, 0);
CGPathAddLineToPoint(pathLine, NULL, 100, 100);
③将路径添加到设备上下文中
CGContextAddPath(ctr, pathLine);
④渲染之后销毁路径
CGPathRelease(pathArc);
- void drawPath()
- {
- CGContextRef ctr = UIGraphicsGetCurrentContext();
- //1.创建路径
- CGMutablePathRef pathLine = CGPathCreateMutable();
- //2.在路径上绘制图形
- CGPathMoveToPoint(pathLine, NULL, 0, 0);
- CGPathAddLineToPoint(pathLine, NULL, 100, 100);
- //3.将路径添加到图形上下文中
- CGContextAddPath(ctr, pathLine);
- CGMutablePathRef pathArc = CGPathCreateMutable();
- CGPathAddEllipseInRect(pathArc, NULL, CGRectMake(200, 200, 100, 100));
- CGContextAddPath(ctr, pathArc);
- CGContextStrokePath(ctr);
- //4.渲染之后,销毁Path。
- //一般在含有Create/copy/retain的函数中,都要用release销毁
- CGPathRelease(pathArc);
- CGPathRelease(pathLine);
- }