ios 圆形进度条


啥也不说了,直接上代码

-(void)circlePath{

    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:100 startAngle:0 endAngle:(_progress/100)*M_PI*2 clockwise:YES];

    

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];

    shapeLayer.frame = self.view.bounds;

    shapeLayer.path = circlePath.CGPath;

    shapeLayer.opacity = 1.0f;

    shapeLayer.lineCap = kCALineCapRound;

    shapeLayer.lineWidth = 5.0f;

    shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;

    shapeLayer.fillColor = [UIColor clearColor].CGColor;

    [self.view.layer addSublayer:shapeLayer];

    

    

    NSMutableArray *colors = [NSMutableArray array];

    for (NSInteger i = 0; i <= 360; i += 5) {

        UIColor *color = [UIColor colorWithHue:1.0*i/360.0 saturation:1.0 brightness:1.0 alpha:1.0];

        [colors addObject:(id)color.CGColor];

    }

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];

    gradientLayer.frame = self.view.bounds;

    gradientLayer.colors = colors;

    gradientLayer.mask = shapeLayer;

    gradientLayer.startPoint = CGPointMake(0, 0);

    gradientLayer.endPoint = CGPointMake(1, 0);

    [self.view.layer addSublayer:gradientLayer];

    

    _textLayer = [CATextLayer layer];

    float width = [UIScreen mainScreen].bounds.size.width;

    float height = [UIScreen mainScreen].bounds.size.height;

    _textLayer.frame = CGRectMake(width/2-30, height/2, 100, 100);

    _textLayer.foregroundColor = [UIColor redColor].CGColor;

    _textLayer.fontSize = 14.0f;

    [self.view.layer addSublayer:_textLayer];

    

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

    basicAnimation.duration = 5.0f;

    basicAnimation.fromValue = @0;

    basicAnimation.toValue = @1;

    [shapeLayer addAnimation:basicAnimation forKey:@"key"];

}


显示进度百分比

    self.progress = 75;

    [self circlePath];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01*3  repeats:YES block:^(NSTimer * _Nonnull timer) {

        if (_count < _progress) {

            _count ++;

            _textLayer.string = [NSString stringWithFormat:@"%.f%%",_count];

        }

    }];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值