zoukankan      html  css  js  c++  java
  • Quartz2D基本图形绘制的3种方法详解

    #pragma mark - 绘图的几种方式

    #pragma mark - 绘图第三种方式

    1.#pragma mark - 最原始的绘图方式

    - (void)drawLine

    {

    // 1.获取图形上下文

    // 目前我们所用的上下文都是以UIGraphics

    // CGContextRef Ref:引用 CG:目前使用到的类型和函数 一般都是CG开头 CoreGraphics

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 2.描述路径

    // 创建路径

    CGMutablePathRef path = CGPathCreateMutable();

    // 设置起点

    // path:给哪个路径设置起点

    CGPathMoveToPoint(path, NULL, 50, 50);

    // 添加一根线到某个点

    CGPathAddLineToPoint(path, NULL, 200, 200);

    // 3.把路径添加到上下文

    CGContextAddPath(ctx, path);

    // 4.渲染上下文

    CGContextStrokePath(ctx);

    }

    2.#pragma mark - 绘图第二种方式

    - (void)drawLine1

    {

    // 获取上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 描述路径

    // 设置起点

    CGContextMoveToPoint(ctx, 50, 50);

    CGContextAddLineToPoint(ctx, 200, 200);

    // 渲染上下文

    CGContextStrokePath(ctx);

    }

    3.// 贝瑟尔路径

    - (void)drawLine2

    {

    // UIKit已经封装了一些绘图的功能

    // 创建路径

    UIBezierPath *path = [UIBezierPath bezierPath];

    // 设置起点

    [path moveToPoint:CGPointMake(50, 50)];

    // 添加一根线到某个点

    [path addLineToPoint:CGPointMake(200, 200)];

    // 绘制路径

    [path stroke];

    //    NSLog(@"%@",NSStringFromCGRect(rect));

    }

    绘制曲线的属性设置

    1.//UIKit封装好的框架-贝塞尔曲线属性设置

    - (void)drawUIBezierPathState

    {

    UIBezierPath *path = [UIBezierPath bezierPath];

    [path moveToPoint:CGPointMake(50, 50)];

    [path addLineToPoint:CGPointMake(200, 200)];

    path.lineWidth = 10;

    [[UIColor redColor] set];

    [path stroke];

    UIBezierPath *path1 = [UIBezierPath bezierPath];

    [path1 moveToPoint:CGPointMake(0, 0)];

    [path1 addLineToPoint:CGPointMake(30, 60)];

    [[UIColor greenColor] set];

    path1.lineWidth = 3;

    [path1 stroke];

    }

    2.原生绘制的图形的具体属性设置

    - (void)drawCtxState

    {

    // 获取上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 描述路径

    //起点

    CGContextMoveToPoint(ctx, 50, 50);

    CGContextAddLineToPoint(ctx, 100, 50);

    // 设置起点

    CGContextMoveToPoint(ctx, 80, 60);

    // 默认下一根线的起点就是上一根线终点

    CGContextAddLineToPoint(ctx, 100, 200);

    // 设置绘图状态,一定要在渲染之前

    // 颜色

    [[UIColor redColor] setStroke];

    // 线宽

    CGContextSetLineWidth(ctx, 5);

    // 设置连接样式

    CGContextSetLineJoin(ctx, kCGLineJoinBevel);

    // 设置顶角样式

    CGContextSetLineCap(ctx, kCGLineCapRound);

    // 渲染上下文

    CGContextStrokePath(ctx);

    }

  • 相关阅读:
    MVC思想-程序的控制流程-Struts2和SpringMVC黑马流程图
    代理模式
    显卡
    感悟:Java新手一点想法
    java企业级开发的实质就是前台后台如何交互的-各个对象之间如何交互,通信的-程序执行的流程是怎样的
    $.ajax()方法详解--极快瑞中的阿贾克斯函数
    初学者必读之AJAX简单实例2
    初学者必读原生AJAX-异步的javaScript和XML
    c#输入方法名来调用方法(反射)
    unity接入讯飞教程
  • 原文地址:https://www.cnblogs.com/CJH5209/p/6029765.html
Copyright © 2011-2022 走看看