绘画画圆

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        self.frame = frame;

        _lineWidth = 3;

        self.progress = 0;

    }

    returnself;

}

- (void)updateProgress:(float)pro

{

    self.progress = pro;

    [selfsetNeedsDisplay];

//绘画

- (void)drawRect:(CGRect)rect {

    

    CGRect allRect = self.frame;//自身大小

    CGContextRef context = UIGraphicsGetCurrentContext();//获取绘画上下文

    CGContextSetStrokeColorWithColor(context, [UIColorcolorWithHex:@"#0079ff"].CGColor);//设置绘画颜色

    float x = (allRect.size.width / 2);

    float y = (allRect.size.height / 2);//获取圆心点

    CGContextSetLineWidth(context, _lineWidth);//设置线条宽度

//     CGContextSetLineCap(context, kCGLineCapRound);//设置线冒

    CGContextMoveToPoint(context, x, _lineWidth/2.0);// 把绘画的起始点移到园的顶部

                                     //圆心点 //半径   //开始角度     //结束角度 //顺时针

    CGContextAddArc(context, x, y, self.frame.size.width/2 - _lineWidth/2.0, -(M_PI*1/2), - M_PI* 1/2 + (2 * self.progress * M_PI), 0); ///绘画的坐标与数学的正坐标不一样,计算弧度的时候是顺时针为正弧度,逆时针是负弧度

    CGContextStrokePath(context);//完成行程路径开始绘画

}

原文地址:https://www.cnblogs.com/leevaboo/p/3230050.html