您的位置:首页 > 移动开发 > IOS开发

【深入浅出IOS开发】使用路径进行绘制图形

2015-03-31 09:13 381 查看
①创建路径:

 CGMutablePathRef pathLine = CGPathCreateMutable();

②在路径上绘制图形:

CGPathMoveToPoint(pathLine, NULL, 0, 0);

 CGPathAddLineToPoint(pathLine, NULL, 100, 100);

③将路径添加到设备上下文中

CGContextAddPath(ctr, pathLine);

④渲染之后销毁路径

 CGPathRelease(pathArc);

[objc] view
plaincopy

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);  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息