CGContextRef 使用小记

1. 用CGContextRef 画文字

在 UIView的 - (void)drawRect:(CGRect)rect {} 方法中进行

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetShouldAntialias(context, YES); // 抗锯齿
    CGContextSetLineWidth(context, 1.0f); //设置线宽

    /*写文字*/
        CGContextSetRGBFillColor (context,  1, 0, 0, 1.0);//设置填充颜色
        UIFont  *font = [UIFont boldSystemFontOfSize:15.0];//设置文本字体大小
        NSDictionary *attribute = @{NSFontAttributeName:wordFont,NSForegroundColorAttributeName: fontColor};
        [@"文字" drawInRect:CGRectMake(10, 20, 80, 20) withAttributes:attribute];
2. 画圆

    /** 画圆 */
    //void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
    // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。

CGContextSetRGBStrokeColor(context,1,0,0,1.0);//画笔线的颜色 不设置的话是黑色
此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
原文地址:https://www.cnblogs.com/liuw-flexi/p/9029168.html