首页 > Web开发 > 详细

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

时间:2015-07-02 20:45:52      阅读:159      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!