gpt4 book ai didi

ios - 自定义圆圈进度 View IOS

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:19 25 4
gpt4 key购买 nike

我正在尝试创建一个用计时器更新的循环进度 View 。我正在尝试获得 4 个不同颜色的部分。我已经设法用一种颜色更新圆圈,但我无法弄清楚如何将它分成 4 个四分之一圆圈。

@implementation CircularProgressBar
- (void)drawRect:(CGRect)rect
{

UIBezierPath* bezierPath = [UIBezierPath bezierPath];

// Create our arc, with the correct angles
[bezierPath addArcWithCenter:CGPointMake(160, 180)
radius:120
startAngle:0
endAngle: DEGREES_TO_RADIANS(360)
clockwise:YES];

// Set the display for the path, and stroke it
bezierPath.lineWidth = 12;
[[UIColor whiteColor] setStroke];
[bezierPath stroke];

UIBezierPath* progressPath = [UIBezierPath bezierPath];

// Create our arc, with the correct angles
[progressPath addArcWithCenter:CGPointMake(160, 180)
radius:120
startAngle:-M_PI_2
endAngle:-M_PI_2 + (2/M_PI) * self.progress
clockwise:YES];

// Set the display for the path, and stroke it
progressPath.lineWidth = 12;
[[UIColor redColor] setStroke];
[progressPath stroke];

UIBezierPath* progressPath1 = [UIBezierPath bezierPath];

// Create our arc, with the correct angles
[progressPath1 addArcWithCenter:CGPointMake(160, 180)
radius:120
startAngle:-M_PI_2 + (2/M_PI)
endAngle:M_PI_2* self.progress1/
clockwise:YES];

// Set the display for the path, and stroke it
progressPath1.lineWidth = 12;


[[UIColor grayColor] setStroke];
[progressPath1 stroke];

}

-(void)setProgress:(CGFloat)progress {
//update progress with timer
if (progress != _progress) {
_progress = progress;
if(progress > 1.1)
_progress1=_progress;
[self setNeedsDisplay];
}

}

定时器类

-(float) progress {
return (float)self.count/450.0;
}

计时器为 1800 秒。除以 4 为每节 450 秒

最佳答案

我为此创建了一个小型库,非常灵活,有很多选项:https://github.com/kirualex/KAProgressLabel

一个简单的配置如下所示:

[self.pLabel setTrackWidth: 2.0];
[self.pLabel setProgressWidth: 4];
self.pLabel.fillColor = [[UIColor lightGrayColor] colorWithAlphaComponent:.3];
self.pLabel.trackColor = self.startSlider.tintColor;
self.pLabel.progressColor = [UIColor greenColor];

关于ios - 自定义圆圈进度 View IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22988783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com