1、CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文
CGContextMoveToPoint 开始画线
CGContextAddLineToPoint 画直线
CGContextAddEllipseInRect 画一椭圆
CGContextSetLineCap 设置线条终点形状
CGContextSetLineDash 画虚线
CGContextAddRect 画一方框
CGContextStrokeRect 指定矩形
CGContextStrokeRectWithWidth 指定矩形线宽度
CGContextStrokeLineSegments 一些直线
2、环境配置:
CGContextBeginPath(ctx);/* Begin a new path. The old path is discarded. */ 开始配置一条新的路径
CGContextMoveToPoint(CGContextRef cg_nullable c,CGFloat x, CGFloat y) /* Start a new subpath at point `(x, y)' in the context's path. */ 在layer上添加一个新的子路径,设置起点(x,y)。
CGContextAddLineToPoint(CGContextRef cg_nullable c, CGFloat x, CGFloat y)/* Append a straight line segment from the current point to `(x, y)'. */*从当前点追加一条直线段到(x,y)。* /
CGContextStrokePath(CGContextRef cg_nullable c)/* Stroke the context's path. */* 设置上下文路径。画线* /
UIGraphicsPushContext(ctx);环境配置压栈,保存
UIGraphicsPopContext();回复环境配置