暂时还没有在项目中使用过Quart2D,但感觉好强大,学了一些的基本的知识
所有的绘图都是基于上下文的,上下文,保存和输出所画的图像,可以输出到自己的view上打印机等
- (void)drawRect:(CGRect)rect {
CGContextRef ref =UIGraphicsGetCurrentContext();//获取到layer的上下文,c语言的方法
//绘图(直线)
CGContextMoveToPoint(ref, 10, 10);//起点
CGContextAddLineToPoint(ref, 100, 100);//终点
CGContextAddLineToPoint(ref, 30, 100);
--------绘制文字
NSString *str =@"今天非常的开心";
NSMutableDictionary*dic =[[NSMutableDictionary alloc]init];
dic[NSForegroundColorAttributeName] =[UIColor greenColor];
[str drawAtPoint:CGPointMake(20, 10) withAttributes:dic];
//设置绘图状态
CGContextSetRGBStrokeColor(ref, 1.0, 0, 0, 1.0); //绘制图形到view上
//直线的宽度
CGContextSetLineWidth(ref, 20);
//直线的头的样式
CGContextSetLineCap(ref, kCGLineCapRound);
//c语言设置颜色
CGContextSetRGBFillColor(tea, 1.0, 0, 0, 1.0);
//oc的方法设置颜色
[[UIColor purpleColor]setFill];
//设置绘图颜色可设置实心和空心
[[UIColor redColor]set]; //转角
CGContextSetLineJoin(ref, kCGLineJoinRound);
CGContextStrokePath(ref);
-----------------画圆弧
CGContextRef ref =UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ref, 10, 20);
CGContextAddLineToPoint(ref, 50, 20);
//0顺时针、1逆时针
CGContextAddArc(ref, 10, 20, 50, 0, M_2_PI, 0);
CGContextClosePath(ref);
[[UIColor greenColor]set];
CGContextStrokePath(ref);