環形進度條的實現
阿新 • • 發佈:2019-02-07
//新增程式碼
在所需要展示進度條的類裡引入類
#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];
}