Quartz2D

暂时还没有在项目中使用过Quart2D,但感觉好强大,学了一些的基本的知识


所有的绘图都是基于上下文的,上下文,保存和输出所画的图像,可以输出到自己的view上打印机等


- (void)drawRect:(CGRect)rect {
   
    CGContextRef  ref =UIGraphicsGetCurrentContext();//获取到layer的上下文,c语言的方法
    
    //绘图(直线)

    CGContextMoveToPoint(ref, 10, 10);//起点
    
    CGContextAddLineToPoint(ref, 100, 100);//终点
    
    CGContextAddLineToPoint(ref, 30, 100);
--------绘制文字


NSString *str =@"今天非常的开心";
    NSMutableDictionary*dic =[[NSMutableDictionary alloc]init];
    
    dic[NSForegroundColorAttributeName] =[UIColor greenColor];
    
    [str drawAtPoint:CGPointMake(20, 10) withAttributes:dic];

   
    //设置绘图状态
    
    CGContextSetRGBStrokeColor(ref, 1.0, 0, 0, 1.0);    //绘制图形到view上
    
    //直线的宽度
    CGContextSetLineWidth(ref, 20);
    
    //直线的头的样式
    CGContextSetLineCap(ref,  kCGLineCapRound);
   

//c语言设置颜色

CGContextSetRGBFillColor(tea, 1.0, 0, 0, 1.0);
    
    //oc的方法设置颜色
    
    [[UIColor purpleColor]setFill];
    
    //设置绘图颜色可设置实心和空心
    
    [[UIColor redColor]set];    //转角
    CGContextSetLineJoin(ref, kCGLineJoinRound);
    
    
    CGContextStrokePath(ref);

    -----------------画圆弧

   
    CGContextRef ref =UIGraphicsGetCurrentContext();
    
    CGContextMoveToPoint(ref, 10, 20);
    
    CGContextAddLineToPoint(ref, 50, 20);
    //0顺时针、1逆时针
    CGContextAddArc(ref, 10, 20, 50, 0, M_2_PI, 0);
    
    CGContextClosePath(ref);
    [[UIColor greenColor]set];
    CGContextStrokePath(ref);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值