• 画线、简单图形总结(draw)


    一、描绘数字

       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));

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

    三、画扇形

    #define radians(x) ((x)*M_PI / 180.0)

    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(110, 35) withFont:[UIFontsystemFontOfSize:14]];

  • 相关阅读:
    如何在Wyn Enterprise中实现数据脱敏
    报表工具中如何在表格实现累计同比
    同一报表,根据不同条件,执行不同Sql
    报表单元格内超过一定长度显示省略号,鼠标悬浮显示全部内容
    报表实现按照天/周/月/季度/年进行快速查询,并且根据快速选择条件进行汇总统计
    典型报表设计:项目应收款统计,行分组不汇总、分组内过滤、行记录和汇总计算
    报表表格实现自定义序号
    报表中常见模糊查询实现
    如何在仪表板表格中将日期显示为文本格式?
    MySQL动态数据源的实现
  • 原文地址:https://www.cnblogs.com/swallow37/p/2846000.html
Copyright © 2020-2023  润新知