CGPath CGContext UIBezierPath的比较
来源:互联网 发布:golang base64 decode 编辑:程序博客网 时间:2024/05/22 12:49
//// PathView.m// Qauze//// Created by apple on 16/6/2.// Copyright © 2016年 李重阳. All rights reserved.//#import "PathView.h"@implementation PathView- (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor blueColor]; } return self;}- (void)drawRect:(CGRect)rect { [self CGPath]; [self CGContext]; [self bezier]; [self drawRound];}/* * 一: CGPath **/- (void)CGPath { CGContextRef ref = UIGraphicsGetCurrentContext(); CGMutablePathRef pathRef = CGPathCreateMutable(); //1.设置起点 CGPathMoveToPoint(pathRef, nil, 5, 5); //2.加入线 CGPathAddLineToPoint(pathRef, nil, 50, 50); //3.把path 放到contextRef 中 CGContextAddPath(ref, pathRef); CGPathRelease(pathRef); [[UIColor redColor]setStroke];// CGContextSetStrokeColorWithColor(ref, [UIColor redColor].CGColor); /* *这句话必须加上去 否则 不会开始绘制 *这句话是开始绘制CGPath路径 **/ CGContextStrokePath(ref);}/* * 二: 直接用CGContext 绘制 **/- (void)CGContext { CGContextRef ref = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(ref, 50, 50); CGContextAddLineToPoint(ref, 100, 100); CGContextAddLineToPoint(ref, 10, 60); CGContextSetLineWidth(ref, 5); CGContextSetLineCap(ref, kCGLineCapRound); CGContextSetLineJoin(ref, kCGLineJoinBevel); [[UIColor yellowColor]setFill]; [[UIColor cyanColor]setStroke]; /* * 3种方法绘制 path * 1.CGContextFillPath(ref); 绘制填充 * 2.CGContextStrokePath(ref); 绘制 笔触 * 3.CGContextDrawPath(ref, kCGPathFillStroke); 绘制填充和笔触 **/ CGContextDrawPath(ref, kCGPathFillStroke);}/* * 贝塞尔曲线 **/- (void)bezier { UIBezierPath * path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(100,100)]; [path addLineToPoint:CGPointMake(200, 100)]; [path addLineToPoint:CGPointMake(150, 200)]; [path setLineCapStyle:kCGLineCapRound]; [path setLineJoinStyle:kCGLineJoinBevel]; [path setLineWidth:5]; [[UIColor redColor]setFill]; [[UIColor yellowColor]setStroke]; [path stroke]; [path fill]; [path closePath];}/* * 贝塞尔曲线绘制 圆 ,椭圆 ,扇形 **/- (void)drawRound { //绘制圆 UIBezierPath * path = [UIBezierPath bezierPath]; [path addArcWithCenter:CGPointMake(100, 100) radius:50 startAngle:0 endAngle:M_PI*1.5 clockwise:YES]; [path setLineWidth:10]; [[UIColor yellowColor]setStroke]; [path stroke]; //绘制椭圆 UIBezierPath * path1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 200)]; [path1 setLineWidth:5]; [path1 stroke];}@end
0 0
- CGPath CGContext UIBezierPath的比较
- CGContextRef,CGPath 和 UIBezierPath的区别
- iOS绘图系列六:利用CAShapeLayer和UIBezierPath或者CGPath绘制想要的图像
- UIBezierPath和CGContext类中的方法
- UIBezierPath和CGContext类中的方法
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- 39.两种定时器 CGPath 画四边形 UIBezierPath
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- iOS: 使用CGContextRef,CGPath和UIBezierPath来绘画
- [ios]ios画线 使用CGContextRef,CGPath和UIBezierPath来绘画
- CoreGraphic&UIBezierPath绘图比较
- CGContext的基本认识
- CGContext的基本认识
- CGContext的基本认识
- CGContext的基本认识
- CGContext的基本认识
- jms入门
- JSP页面处理日期格式
- OpenResty学习笔记(二)函数
- 第0章:计算机概论
- STL面试题
- CGPath CGContext UIBezierPath的比较
- iOS开发------XML原生解析(NSXMLParser篇)
- iOS 基础篇7—实现UItableview控件数据刷新
- JSON-WEB-TOKENS
- leetcode 172. Factorial Trailing Zeroes
- Java常用排序算法之快速排序
- unity中FiexdUpdate和Update以及LateUpdate的区别
- linux编程学习--常见文件目录操作
- 哈弗曼树与哈弗曼树编码