Core Graphics - 18233135268/iOS-develop GitHub Wiki


Table of Contents

绘图上下相关函数


//获取当前绘图上下文,绘图的第一步,可以理解为画布
UIGraphicsGetCurrentContext():

//保存上下文状态,这个函数的作用是将当前图形状态推入堆栈。之后,您对图形状态所做的修改会影响随后的描画操作,但不影响存储在堆栈中的拷贝。
CGContextSaveGState():

//恢复上下文状态,通过这个函数把堆栈顶部的状态弹出,返回到之前的图形状态。和CGContextSaveGState()配对使用。
CGContextRestoreGState(): 

:CGContextSaveGState()和CGContextRestoreGState()使用举例:整个绘图都是红色,但是中间需要有个图是灰色,这种场景就可以使用这两个函数处理了

绘图路径相关函数


//定位到某个点
CGContextMoveToPoint(): 

//画线,添加一条直线到一个点
CGContextAddLineToPoint(): 

//画矩形
CGContextAddRect():

//内切圆或者椭圆
CGContextAddEllipseInRect();

//一个控制点的贝塞尔曲线
CGContextAddQuadCurveToPoint():

//两个控制点的贝塞尔曲线
CGContextAddCurveToPoint();

//画曲线
CGContextAddArc():

//画虚线
CGContextSetLineDash():

//画指定的路径
CGContextAddPath():

//闭合当前的路径
CGContextClosePath():

绘图设置相关函数


//设置线条的宽度
CGContextSetLineWidth():

//设置线条的颜色(通过UIColor)
CGContextSetStrokeColorWithColor():

//设置线条的颜色(通过RGB值)
CGContextSetRGBStrokeColor():

//设置图形填充颜色(三色值和透明度)
CGContextSetFillColor():

//设置填充颜色(UIColor值)
CGContextSetFillColorWithColor():

//设置填充颜色(RGB值)
CGContextSetRGBFillColor():

//设置透明度
CGContextSetAlaha():

//是否开启抗锯齿
CGContextSetShouldAntialias():

//设置直线端点的样式
CGContextSetLineCap():

//设置直线连接点的样式
CGContextSetLineJoin():

//设置阴影(尺寸和模糊度)
CGContextSetShadow():

//设置阴影和阴影的颜色
CGContextSetShadowWithColor():

图形填充相关函数


//填充一个矩形
CGContextFillRect():

//描边
CGContextStrokePath():

//只填充不描边
CGContextFillPath():

//使用奇偶规则填充
CGContextEOFillPath():

//绘制路径(可以选择填充的样式)
CGContextDrawPath():

使用CGContextRef创建


//开始画路径
CGContextBeginPath

//移动到某一点
CGContextMoveToPoint

//画直线
CGContextAddLineToPoint

//画饼图
CGContextAddCurveToPoint

//画椭圆
CGContextAddEllipseInRect

//画圆
CGContextAddARC

//画方框
CGContextAddRect

//封闭当前路径
CGContextClosePath

使用CGPathRef创建


//其余的与上边的函数一一对应
CGPathCreateMutable

CGPathMoveToPoint

CGPathAddLineToPoint

CGPathAddCurveToPoint

CGPathAddEllipseInRect

CGPathAddArc

CGPathAddRect

CGPathCloseSubpath

//添加一个新的路径
CGContextAddPath

使用UIBezierPath创建


//创建path
+(instancetype)bezierPath;

//矩形
+(instancetype)bezierPathWithRect:(CGRect)rect;

//以矩形框为切线画圆
+(instancetype)bezierPathWithOvalInRect:(CGRect)rect;

//带圆角的矩形框
+(instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;

//画圆弧
+(instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;

//移动到某一点
-(void)moveToPoint:(CGPoint)point;

//添加直线
-(void)addLineToPoint:(CGPoint)point;

//带一个基准点的曲线
-(void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;

//带两个基准点的曲线
-(void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;

//封闭路径
-(void)closePath;

//添加新的路径
-(void)appendPath:(UIBezierPath *)bezierPath;

//渲染
//填充Fill:将路径内部填充渲染
-(void)fill;
//描边Stroke:不填充,只对路径进行渲染
-(void)stroke;

⚠️ **GitHub.com Fallback** ⚠️