IOS学习之Quartz2D

Quartz2D绘图的代码步骤

1. 获得图形上下文

CGContextRef ctx= UIGraphicsGetCurrentContext();

2. 拼接路径(下面代码是搞一条线段)

CGContextMoveToPoint(ctx,10, 10);

CGContextAddLineToPoint(ctx,100, 100);

3. 绘制路径

CGContextStrokePath(ctx);//CGContextFillPath(ctx);


常用拼接路径函数

新建一个起点

voidCGContextMoveToPoint(CGContextRef c, CGFloat x, CGFloaty)

添加新的线段到某个点

voidCGContextAddLineToPoint(CGContextRefc, CGFloatx, CGFloaty)

添加一个矩形

voidCGContextAddRect(CGContextRefc, CGRect rect)

添加一个椭圆

voidCGContextAddEllipseInRect(CGContextRefcontext, CGRect rect)

添加一个圆弧

voidCGContextAddArc(CGContextRefc, CGFloatx, CGFloaty,

 CGFloatradius, CGFloatstartAngle, CGFloatendAngle, intclockwise)

Mode 参数决定绘制的模式

voidCGContextDrawPath(CGContextRefc, CGPathDrawingMode mode)

绘制空心路径

voidCGContextStrokePath(CGContextRefc)

绘制实心路径

voidCGContextFillPath(CGContextRefc)

提示:一般以CGContextDrawCGContextStrokeCGContextFill开头的函数,都是用来绘制路径的


图形上下文栈的操作

将当前的上下文 copy 一份 , 保存到栈顶 ( 那个栈叫做 图形上下文栈 ”)

voidCGContextSaveGState(CGContextRef c)

将栈顶的上下文出栈 , 替换掉当前的上下文

voidCGContextRestoreGState(CGContextRef c)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值