• CoreGraphics 画图,(转燕羽天空)


    一、描绘数字

       CGContextRef context = UIGraphicsGetCurrentContext(); //画布

       CGContextSaveGState(context);

        NSString* text = @"15";

        NSString* fontname = @"Helvetica";

        CGContextSelectFont(context, [fontname UTF8String], 18.0, kCGEncodingMacRoman);

        [[UIColorblueColor] setFill];

        CGContextSetShouldAntialias(context, true);//让字体渲染比较清晰提高画质以使之柔和

        CGContextSetTextDrawingMode(context, kCGTextFill);

        //kCGTextClip kCGTextInvisible这样中间没数字 kCGTextFill kCGTextFillClip有数字

        //stroke描边kCGTextFillStroke kCGTextFillStrokeClip数字黑白相映

        // kCGTextStroke kCGTextStrokeClip数字为空心的黑边

        CGContextSetTextMatrix (context, CGAffineTransformMake(1, 0, 0, -1, 0, 0));

        //从文本空间到用户控件的转换矩阵删除的话数字是倒放的

        CGContextShowTextAtPoint(context, 10.0f,

                                 20.0f,

                                 [text cStringUsingEncoding:NSASCIIStringEncoding], text.length); //绘制文本

        CGContextRestoreGState(context);

    二、画圆

    static inline void drawArc(CGContextRef ctx, CGPoint point, UIColor* color, NSInteger radius) {//画圆

        CGContextSetFillColor(ctx, CGColorGetComponents( [color CGColor]));

        CGContextFillEllipseInRect(ctx, CGRectMake(point.x - radius, point.y - radius, radius * 2, radius * 2));

    }//比下面通过扇形画要快

    三、画扇形

    static inline void drawArc(CGContextRef ctx, CGPoint point, float angle_start, float angle_end, UIColor* color) {

        CGContextMoveToPoint(ctx, point.x, point.y);

        CGContextSetFillColor(ctx, CGColorGetComponents( [color CGColor]));

        CGContextAddArc(ctx, point.x, point.y, radius,  angle_start, angle_end, 0);

        //CGContextClosePath(ctx);

        CGContextFillPath(ctx);

    }

     CGContextRef context = UIGraphicsGetCurrentContext(); //画布

    CGPoint point = CGPointMake(20, 20);

     float angle_start = radians(0.0);

     float angle_end = radians(360.0);

    drawArc(context, point, angle_start, angle_end, [UIColor redColor]);

     四、画线

    CGContextRef context = UIGraphicsGetCurrentContext(); //画布        

    CGContextSetRGBStrokeColor(context, 204.0/255.0, 102.0/255.0, 0.0/255.0, 1.0); //笔色

    CGContextSetLineWidth(context, 0.8); //线宽

    CGContextMoveToPoint(context, 0.0, 0.0);//起始点

    CGContextAddLineToPoint(context, 0.0, 100.0);//终点

    CGContextStrokePath(context);//画

    五、画矩形

     CGContextRef context = UIGraphicsGetCurrentContext(); //画布

     CGRect bgRect = CGRectMake(batchCodeLabelWidth + ballHeigth * k , ballHeigth * i, ballHeigth, ballHeigth);//区域

      CGContextSetRGBFillColor(context, 241.0/255.0, 241.0/255.0, 241.0/255.0, 1);//颜色

       CGContextAddRect(context, bgRect);

       CGContextDrawPath(context, kCGPathFillStroke);

    六、画汉字

    直接使用NSString的方法:

    [@"哈哈"  drawAtPoint:CGPointMake(11035withFont:[UIFontsystemFontOfSize:14]];

  • 相关阅读:
    Jmeter(二十七) 从入门到精通 Jmeter Http协议录制脚本(详解教程)
    Jmeter(二十六) 从入门到精通 搭建开源论坛JForum(详解教程)
    [Erlang0003][OTP] Efficiency Guide User's Guide > Common Caveats
    [Erlang0008][OTP] 高效指南 表和数据库(ets mnesia)
    [Erlang0004][OTP] 高效指南 二进制的构造和匹配(1)
    [Erlang0002][OTP] Efficiency Guide User's Guide > The Eight Myths of Erlang Performance
    [Erlang0010][News]OTP 技术委员会 影响R16的决策 (OTP Technical Board Decisions affecting R16 翻译)
    [Erlang0007][OTP] 高效指南 函数
    [Erlang0005][OTP] 高效指南 二进制的构造和匹配(2)
    [Erlang0001][OTP] Efficiency Guide User's Guide>Introduction
  • 原文地址:https://www.cnblogs.com/guligei/p/3489339.html
Copyright © 2020-2023  润新知