学习IOS开发UI篇--Quartz2D基本绘图

it2022-05-09  33

  Quartz2D绘图的代码步骤

1.获得图形上下文CGContextRef ctx = UIGraphicsGetCurrentContext();2.拼接路径(下面代码是搞一条线段)CGContextMoveToPoint(ctx, 10, 10);CGContextAddLineToPoint(ctx, 100, 100);3.绘制路径CGContextStrokePath(ctx); // CGContextFillPath(ctx);  常用拼接路径函数

1.新建一个起点void CGContextMoveToPoint(CGContextRef c, CGFloat x, CGFloat y)2.添加新的线段到某个点void CGContextAddLineToPoint(CGContextRef c, CGFloat x, CGFloat y)3.添加一个矩形void CGContextAddRect(CGContextRef c, CGRect rect)4.添加一个椭圆void CGContextAddEllipseInRect(CGContextRef context, CGRect rect)5.添加一个圆弧void CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y,  CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise)  常用绘制路径函数1.Mode参数决定绘制的模式void CGContextDrawPath(CGContextRef c, CGPathDrawingMode mode)2.绘制空心路径void CGContextStrokePath(CGContextRef c)3.绘制实心路径void CGContextFillPath(CGContextRef c)提示:一般以CGContextDraw、CGContextStroke、CGContextFill开头的函数,都是用来绘制路径的

  图形上下文栈的操作

1.将当前的上下文copy一份,保存到栈顶(那个栈叫做”图形上下文栈”)void CGContextSaveGState(CGContextRef c)2.替换掉当前的上下文void CGContextRestoreGState(CGContextRef c)

使用CGContextSclateCTM等方法,一定要在赋值属性前调用

使用CGContextClip时候,一定要在绘制前调用

转载于:https://www.cnblogs.com/zhaoyan/p/3778943.html


最新回复(0)