为了账号安全,请及时绑定邮箱和手机立即绑定

IOS中的循环进度条

IOS中的循环进度条

智慧大石 2019-12-12 13:04:30
我想创建一个圆形的进度条,如下所示:如何使用Objective-C和Cocoa做到这一点?我开始做的是创建UIView和编辑drawRect,但是我有点迷茫。任何帮助将不胜感激。谢谢!
查看完整描述

3 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

我的魔术数字示例(以便更好地理解):


  CAShapeLayer *circle = [CAShapeLayer layer];

  circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(29, 29) radius:27 startAngle:-M_PI_2 endAngle:2 * M_PI - M_PI_2 clockwise:YES].CGPath;

  circle.fillColor = [UIColor clearColor].CGColor;

  circle.strokeColor = [UIColor greenColor].CGColor;

  circle.lineWidth = 4;


  CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];

  animation.duration = 10;

  animation.removedOnCompletion = NO;

  animation.fromValue = @(0);

  animation.toValue = @(1);

  animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

  [circle addAnimation:animation forKey:@"drawCircleAnimation"];


  [imageCircle.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];

  [imageCircle.layer addSublayer:circle];


查看完整回答
反对 回复 2019-12-12
?
茅侃侃

TA贡献1842条经验 获得超21个赞

对于Swift来说,


let circle = UIView(frame: CGRectMake(0,0, 100, 100))


circle.layoutIfNeeded()


let centerPoint = CGPoint (x: circle.bounds.width / 2, y: circle.bounds.width / 2)

let circleRadius : CGFloat = circle.bounds.width / 2 * 0.83


var circlePath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: CGFloat(-0.5 * M_PI), endAngle: CGFloat(1.5 * M_PI), clockwise: true    )


let progressCircle = CAShapeLayer()

progressCircle.path = circlePath.CGPath

progressCircle.strokeColor = UIColor.greenColor().CGColor

progressCircle.fillColor = UIColor.clearColor().CGColor

progressCircle.lineWidth = 1.5

progressCircle.strokeStart = 0

progressCircle.strokeEnd = 0.22


circle.layer.addSublayer(progressCircle)


self.view.addSubview(circle)


查看完整回答
反对 回复 2019-12-12
  • 3 回答
  • 0 关注
  • 719 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信