码迷,mamicode.com
首页 > Web开发 > 详细

利用Quartz2D推图的另一个方法 (使用CGMutalePathRef进行分层次)

时间:2015-07-02 20:48:18      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

 

可以利用 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!