gpt4 book ai didi

ios - 如何自定义矩形进度条?

转载 作者:行者123 更新时间:2023-11-28 18:03:51 24 4
gpt4 key购买 nike

我想用 UIKIT 像吸引图像一样自定义一个矩形进度条。有没有源代码?Cocos2d 与 CCProgressTimer 相同,但我找不到任何 UIKIT 源代码。 Rectangle progress bar

最佳答案

创建一个ShapedLayer

CAShapeLayer *layer = [CAShapeLayer layer];
[layer setStrokeColor:[UIColor greenColor].CGColor];
[layer setLineWidth:10.0f];

[layer setFillColor:[UIColor clearColor].CGColor];

在你想要动画的地方用radious创建一个rect

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 300, 200) cornerRadius:10.0f];
layer.path = path.CGPath;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];

定义动画持续时间

animation.duration = 4.0f;
[layer addAnimation:animation forKey:@"myStroke"];

在要显示的图层上添加动画

[self.view.layer addSublayer:layer];

关于ios - 如何自定义矩形进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15741533/

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