IOS 自界說進度條 ProgressView,好的進度條,讓人心曠神怡,在期待的時刻不是那末焦躁,也算是增長用戶體驗吧!
進度條在IOS開辟中很罕見的,我在項目開辟中也寫過很多多少進度條,有很多多少品種的,條形,圓形等,明天給年夜家總結一種條形的開辟進度條。
簡略思緒:
1.自界說進度條先繼續UIView 樹立一個CustomBarProgressView
2.在.H文件中外漏的辦法《開端的辦法》《初始化的辦法》
3.在.M文件中 應用准時器轉變地位 完成進度條
#後果圖

#部門代碼
-(instancetype)initWithFrame:(CGRect)frame withStartNum:(CGFloat)startNum withEndNum:(CGFloat)endNum withSignNum:(CGFloat)signNum withTime:(CGFloat)time{
if (self = [super initWithFrame:frame]) {
self.startNum = startNum;
self.endNum = endNum;
self.signNum = signNum;
if(time == 0){
self.time = 0.1;
}else{
self.time = time;
}
[self setUpSubViews];
}
return self;
}
- (void)setUpSubViews
{
UIView *backView = [[UIView alloc] init];
backView.backgroundColor =BoomViewColor;
backView.layer.cornerRadius = CornerRadius;
backView.layer.masksToBounds = YES;
[self addSubview:backView];
self.backView = backView;
UIView *fontView = [[UIView alloc] init];
fontView.backgroundColor = UpViewColor;
fontView.layer.cornerRadius = CornerRadius;
fontView.layer.masksToBounds = YES;
[self addSubview:fontView];
self.fontView = fontView;
}
-(void)progressViewStart{
if (self.timer == nil) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.timer = [NSTimer scheduledTimerWithTimeInterval:self.time target:self selector:@selector(changeProgressViewFrame:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
});
}
}
-(void)changeProgressViewFrame:(NSTimer *)timer{
//地位盤算
CGFloat signProgress = (self.signNum - self.startNum) / (self.endNum - self.startNum);
NSLog(@"==>>>%f",self.progress);
if (self.progress >= signProgress){
[self.timer invalidate];
self.timer = nil;
return;
}
self.progress += 0.01;
[self setNeedsLayout];
}
-(void)layoutSubviews{
[super layoutSubviews];
NSLog(@"==>>>%f",self.progress);
self.backView.frame = self.bounds;
self.fontView.frame = self.bounds;
self.fontView.width = self.width * self.progress;
}
PS:可以本身增長 進度條則字等修正年夜小 款式
別小視任何人,越不起眼的人。常常會做些讓人想不到的事。。。
感激浏覽,願望能贊助到年夜家,感謝年夜家對本站的支撐!
【IOS 開辟自界說條形ProgressView的實例】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!