环形进度条的实现

环形进度条的实现_第1张图片

环形进度条的实现_第2张图片

//添加代码

https://github.com/danielamitay/DACircularProgress
环形进度条的实现_第3张图片

在所需要展示进度条的类里引入类

#import "DACircularProgressView.h"
#import "DALabeledCircularProgressView.h"

方法的调用与实现

//.h
// Labeled progress views
@property (strong, nonatomic) DALabeledCircularProgressView *labeledProgressView;
@property (strong, nonatomic) UIStepper *stepper;
@property (strong, nonatomic) NSTimer *timer;
//.m
@synthesize stepper = _stepper;
@synthesize timer = _timer;

viewDidLoad中实现
    //进度条的初始化
    self.labeledProgressView = [[DALabeledCircularProgressView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 60.0f, 60.0f)];
    self.labeledProgressView.roundedCorners = NO;
    [self.view addSubview:self.labeledProgressView];

    //修改展示形式
    self.labeledProgressView.trackTintColor = [UIColor grayColor];
    self.labeledProgressView.progressTintColor = [UIColor whiteColor];
    self.labeledProgressView.thicknessRatio = 1.0f;
    self.labeledProgressView.clockwiseProgress = NO;
    [self startAnimation];

//自定义一个时间控制器

- (void)startAnimation
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.03
                                                  target:self
                                                selector:@selector(progressChange)
                                                userInfo:nil
                                                 repeats:YES];
}

//进度label的显示

- (void)progressChange
{
    // Labeled progress views
    CGFloat progress = ![self.timer isValid] ? self.stepper.value / 10.0f : self.labeledProgressView.progress + 0.01f;

    [self.labeledProgressView setProgress:progress animated:YES];

    if (self.labeledProgressView.progress >= 1.0f && [self.timer isValid]) {
        [self.labeledProgressView setProgress:0.f animated:YES];
    }
    CGFloat number= self.labeledProgressView.progress*100;
    self.labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%.f%%", number];
}

你可能感兴趣的:(自定义动画)