- (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);
}
绘图的五种方式
最新推荐文章于 2023-09-13 17:06:49 发布