iOS Quartz 2D介绍

来源:互联网 发布:影视制作需要哪些软件 编辑:程序博客网 时间:2024/04/29 06:26
Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统
Quartz 2D能完成的工作
绘制图形 : 线条\三角形\矩形\圆\弧等
绘制文字
绘制\生成图片(图像)
读取\生成PDF
截图\裁剪图片
自定义UI控件
Quartz2D提供了以下几种类型的Graphics Context:
Bitmap Graphics Context
PDF Graphics Context
Window Graphics Context
Layer Graphics Context
Printer Graphics Context
绘图的步骤: 1.获取上下文 2.创建路径(描述路径) 3.把路径添加到上下文 4.渲染上下文
方法1:
CGContextRef ctx = UIGraphicsGetCurrentContext();
    // 描述路径
    // 设置起点
    CGContextMoveToPoint(ctx, 50, 50);
    // cpx:控制点的x
    CGContextAddQuadCurveToPoint(ctx, 150, 20, 250, 50);
    // 渲染上下文
    CGContextStrokePath(ctx);
方法2:贝瑟尔路径
UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(50, 50)];
    [path addLineToPoint:CGPointMake(200, 200)];
    path.lineWidth = 10;
    [[UIColor redColor] set];
    [path stroke];


 // 颜色
    [[UIColor redColor] setStroke];


    // 线宽
    CGContextSetLineWidth(ctx, 5);


    // 设置连接样式
    CGContextSetLineJoin(ctx, kCGLineJoinBevel);


    // 设置顶角样式
    CGContextSetLineCap(ctx, kCGLineCapRound);
1 0