首页 > 移动平台 > 详细

ios绘图之quarz2d

时间:2016-01-23 12:59:28      阅读:188      评论:0      收藏:0      [点我收藏+]
 1 - (void)drawRect:(CGRect)rect
 2 {
 3     // 1.获取上下文
 4     CGContextRef ctx = UIGraphicsGetCurrentContext();
 5    
 6     // 2.创建路径(一个path就代表一条路径)
 7     // 但凡通过quarzt2d中的带有create/ copy / retain 方法创建出来的值都必须手动的释放
 8     CGMutablePathRef path = CGPathCreateMutable();
 9     // 设置起点
10     CGPathMoveToPoint(path, NULL, 10, 10);
11     // 设置终点
12     CGPathAddLineToPoint(path, NULL, 100, 100);
13     // 将路径添加到上下文中
14     CGContextAddPath(ctx, path);
15     
16     // 3.再创建一条路径用于保存圆
17      CGMutablePathRef path2 = CGPathCreateMutable();
18     // 在path中添加画的路径
19     CGPathAddEllipseInRect(path2, NULL, CGRectMake(50, 50, 50, 50));
20     CGContextAddPath(ctx, path2);
21     
22     // 3.渲染‘
23     CGContextStrokePath(ctx);
24     
25     
26     // 释放前面创建的两条路径
27     CGPathRelease(path);
28     CGPathRelease(path2);
29     
30     // 下面这种方式也可以释放路径
31     
32 //    CFRelease(path);
33 //    CFRelease(path2);
34 }

注意:画完后要释放资源

技术分享

ios绘图之quarz2d

原文:http://www.cnblogs.com/PJHome/p/5153049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!