Quartz2D绘图

Quartz2D 

常⽤用拼接路径函数

新建⼀一个起点

void CGContextMoveToPoint(CGContextRefc,CGFloat x, CGFloat y)

添加新的线段到某个点

void CGContextAddLineToPoint(CGContextRefc,CGFloat x, CGFloat y)

添加⼀一个矩形

void CGContextAddRect(CGContextRefc,CGRect rect)

添加⼀一个椭圆

void CGContextAddEllipseInRect(CGContextRefcontext,CGRect rect)

添加⼀一个圆弧

void CGContextAddArc(CGContextRefc,CGFloat x, CGFloat y,

 CGFloat radius, CGFloatstartAngle,CGFloat endAngle, int clockwise)

常⽤用绘制路径函数

 Mode参数决定绘制的模式

void CGContextDrawPath(CGContextRefc,CGPathDrawingMode mode)

绘制空⼼心路径

void CGContextStrokePath(CGContextRefc)

绘制实⼼心路径

void CGContextFillPath(CGContextRefc)

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


图形上下⽂文栈的操作

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

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

void CGContextRestoreGState(CGContextRefc)



// 获取上下文 view
	CGContextRef context = UIGraphicsGetCurrentContext();
    
// 画点
    CGContextMoveToPoint(context, 10, 10);
    
// 设置线宽度
    CGContextSetLineWidth(context, 2);
    CGContextSetRGBStrokeColor(context, 1, 1, 0, 1);
    
// 设置连接点 样式
    CGContextSetLineJoin(context, kCGLineJoinBevel);
    CGContextSetLineCap(context, kCGLineCapRound);
   
// 画直线
    CGContextAddLineToPoint(context, 10, 100);
    CGContextAddLineToPoint(context, 100, 100);
    CGContextAddLineToPoint(context, 100, 10);
    CGContextAddLineToPoint(context, 10, 10);
    
// 画矩形
    CGContextAddRect(context, CGRectMake(100, 10, 100, 100));
    
// 平移
    CGContextTranslateCTM(context,0,100);
// 缩放
    CGContextScaleCTM(context,1.5,1.5);
// 旋转 
    CGContextRotateCTM(context, M_PI * 0.2);
//
    CGContextAddQuadCurveToPoint(context, 100, 200, 10, 10);
    
// 画圆
    CGContextAddEllipseInRect(context, CGRectMake(100, 10, 100, 100));
    
// 画弧
    CGContextAddArc(context, 100, 50, 40, 0 , M_PI, 1);
    CGContextAddArc(context, 100, 50, 40, 0 , M_PI, 0);
//渲染到VIew 不填充  填充
    CGContextStrokePath(context);
//CGContextFillPath(context);
    CGContextClosePath(context);








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值