gpt4 book ai didi

iOS - 带圆角的饼图进度条

转载 作者:行者123 更新时间:2023-11-29 10:29:04 26 4
gpt4 key购买 nike

我需要根据这个设计实现一个进度条:

enter image description here

如您所见,条形本身有一个圆角半径。

这是我当前代码的样子:

enter image description here

那么,怎么做呢?这是我当前的代码:

- (void)animateProgressBarToPercent:(float)percent
{
if (percent > 1.0f) return;

int radius = 42.7f;
int strokeWidth = 7.f;
CGColorRef color = [UIColor someColor].CGColor;
int timeInSeconds = percent * 5;

CGFloat startAngle = 0;
CGFloat endAngle = percent;

CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
circle.position = CGPointMake(self.center.x - radius, self.center.y + strokeWidth);
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = color;
circle.lineWidth = strokeWidth;
circle.strokeEnd = endAngle;

[self.layer addSublayer:circle];

CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = timeInSeconds;
drawAnimation.repeatCount = 1.0;
drawAnimation.removedOnCompletion = NO;

drawAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
drawAnimation.toValue = [NSNumber numberWithFloat:endAngle];

drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
}

最佳答案

circle.lineCap = kCALineCapRound

只需设置您的 CAShapeLayer 的这个属性即可

关于iOS - 带圆角的饼图进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30615689/

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