绘图的五种方式

12 篇文章 0 订阅
- (void)test5{

    //第五种 OC类型
    UIBezierPath *path = [UIBezierPath bezierPath];

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

    [path stroke];
  }

/**
 *  //c+oc第四种方式
 */
- (void)test4{

    //c+oc第四种方式
    //1
    CGContextRef ref = UIGraphicsGetCurrentContext();

    //2
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 20 , 20);

    //创建OC路径
    UIBezierPath *path1 = [UIBezierPath bezierPathWithCGPath:path];
    [path1 addLineToPoint:CGPointMake(300, 20)];

    //将OC路径添加到上下文中
    CGContextAddPath(ref, path1.CGPath);

    //渲染
    CGContextStrokePath(ref);

}

/**
 *  //C和OC 嗲三种方式
 */
- (void)test3{

    //C和OC
    //1.获取上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();

    //2.获取OC的路径对象
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10, 10)];
    [path addLineToPoint:CGPointMake(100, 100)];

    //将路径添加带上下文中 OC对象的路径要转化为C的路径
    CGContextAddPath(ref, path.CGPath);

    //渲染
    CGContextStrokePath(ref);

}

/**
 *  C的第二种方式
 */
- (void)test2{

    //1.获取当前上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();
    //2.拼接路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 100, 100);
    CGPathAddLineToPoint(path, NULL, 100, 0);
    //3.将路径添加到上下文中
    CGContextAddPath(ref, path);

    //4.渲染
    CGContextStrokePath(ref);

    //CGContextFillPath(ref);

}

//1.c的第一种,拼接路径放到上下文中一步完成
- (void)test1{

    //获取当前上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();

    //拼接路径,同时将路径放到上下文中
    //CGMutablePathRef path = CGPathCreateMutable();
    CGContextMoveToPoint(ref, 10, 10);
    CGContextAddLineToPoint(ref, 200, 200);
    CGContextAddLineToPoint(ref, 200, 100);

    CGContextMoveToPoint(ref, 20, 10);
    CGContextAddLineToPoint(ref, 200, 90);
    //CGContextAddPath(ref, path);

    CGContextMoveToPoint(ref, 20, 20);
    CGContextAddLineToPoint(ref, 100, 0);

    //渲染
    CGContextStrokePath(ref);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值