zoukankan      html  css  js  c++  java
  • 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]];

  • 相关阅读:
    windows端口占用处理方法
    【接口】接口测试常见响应码类型(二)
    【接口】SpringBoot+接口开发(一)
    【java+selenium3】Tesseract-OCR识别图片验证码 (十六)
    java读写Txt文件
    【java+selenium3】自动化基础小结+selenium原理揭秘 (十七)
    【java+selenium3】自动化cookie操作+图形验证码处理 (十五)
    【java+selenium3】自动化截图 (十四)
    【Java+selenium3】 Firefox/ IE/ Chrome主流浏览器自动化环境搭建(一)
    【java+selenium3】自动化处理文件上传 (十三)
  • 原文地址:https://www.cnblogs.com/guligei/p/3489339.html
Copyright © 2011-2022 走看看