// // LZCircleView.m // VQU // // Created by CY on 2021/7/9. // Copyright © 2021 leo. All rights reserved. // #import "LZCircleView.h" @implementation LZCircleView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor clearColor]; //默认颜色 self.progerssBackgroundColor=[UIColor lightGrayColor]; self.progerssColor=[UIColor blueColor]; //默认进度条宽度 self.progerWidth=15; } return self; } - (void)setProgress:(CGFloat)progress{ _progress = progress; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect{ //路径 UIBezierPath *backgroundPath = [[UIBezierPath alloc] init]; //线宽 backgroundPath.lineWidth = self.backgroundProgerWidth; //颜色 [self.progerssBackgroundColor set]; //拐角 backgroundPath.lineCapStyle = kCGLineCapRound; backgroundPath.lineJoinStyle = kCGLineJoinRound; CGFloat borderScale = (self.progerWidth - self.backgroundProgerWidth) / 2.0f; //半径 CGFloat radius = (MIN(rect.size.width - borderScale, rect.size.height - borderScale) - self.backgroundProgerWidth) * 0.5; //画弧(参数:中心、半径、起始角度(3点钟方向为0)、结束角度、是否顺时针) [backgroundPath addArcWithCenter:(CGPoint){rect.size.width * 0.5, rect.size.height * 0.5} radius:radius startAngle:M_PI * 1.5 endAngle:M_PI * 1.5 + M_PI * 2 clockwise:YES]; //连线 [backgroundPath stroke]; //路径 UIBezierPath *progressPath = [[UIBezierPath alloc] init]; //线宽 progressPath.lineWidth = self.progerWidth; //颜色 [self.progerssColor set]; //拐角 progressPath.lineCapStyle = kCGLineCapRound; progressPath.lineJoinStyle = kCGLineJoinRound; CGFloat radius1 = (MIN(rect.size.width, rect.size.height) - self.progerWidth) * 0.5; //画弧(参数:中心、半径、起始角度(3点钟方向为0)、结束角度、是否顺时针) [progressPath addArcWithCenter:(CGPoint){rect.size.width * 0.5, rect.size.height * 0.5} radius:radius1 startAngle:M_PI * 1.5 endAngle:M_PI * 1.5 + M_PI * 2 * _progress clockwise:YES]; //连线 [progressPath stroke]; } @end