// // ProgressBarView.m // jiaPei // // Created by apple on 2017/5/12. // Copyright © 2017年 JCZ. All rights reserved. // #import "ProgressBarView.h" @implementation ProgressBarView -(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { CGFloat x,y,w,h; x = 10; y = 0; w = 90; h = 25; UILabel *label = [[UILabel alloc] setxywh]; [label setText:@"" Font:FontTitle TextColor:kTitleColor]; [self addSubview:label]; titleLabel = label; x += w; y += 5; w = kSize.width - x - 60; h = 15; label = [[UILabel alloc] setxywh]; label.backgroundColor = RQlineColor; label.layer.masksToBounds = YES; label.layer.cornerRadius = 7; [self addSubview:label]; allLabel = label; label = [[UILabel alloc] setxywh]; label.backgroundColor = RQ_MAIN_COLOR; label.layer.masksToBounds = YES; label.layer.cornerRadius = 7; [self addSubview:label]; label.hidden = YES; nowLabel = label; x += w; y -= 5; w = 50; h = 25; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:FontTitle TextColor:kTitleColor]; [self addSubview:label]; progressLabel = label; x = 100; y += h; w = kSize.width - x; h = 25; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:FontTitle TextColor:kTitleColor]; [self addSubview:label]; contentLabel = label; } return self; } -(void)setTitleString:(NSString *)titleString { _titleString = titleString; titleLabel.text = titleString; } - (void)setFinishCount:(NSInteger)finishCount { _finishCount = finishCount; [contentLabel removeFromSuperview]; //防止除0 if (_allCount == 0) { _allCount = 50; } progressLabel.text = [NSString stringWithFormat:@"%d/%d",(int)finishCount,(int)_allCount]; nowLabel.hidden = NO; nowLabel.width = allLabel.width * finishCount / _allCount; } - (void)setFinishTime:(NSInteger)finishTime { _finishTime = finishTime; //防止除0 if (_allNeedTime == 0) { _allNeedTime = 240; } NSInteger allHour = _allNeedTime/(_RATIONKS? : 60); NSInteger allMin = _allNeedTime%(_RATIONKS? : 60); NSString *allTimeString = [NSString stringWithFormat:@"%d%@%d分钟",(int)allHour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),(int)allMin]; if (allHour == 0) { allTimeString = [NSString stringWithFormat:@"%d分钟",(int)allMin]; } if (finishTime > 0) { NSInteger hour = finishTime/(_RATIONKS? : 60); NSInteger min = finishTime%(_RATIONKS? : 60); NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",(int)hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),(int)min]; if (hour == 0) { timeString = [NSString stringWithFormat:@"%d分钟",(int)min]; } //在这个地方给进度条赋值 CGFloat progressValue = finishTime*1.0/_allNeedTime*100; progressLabel.text = [NSString stringWithFormat:@"%.0f%%",progressValue]; nowLabel.hidden = NO; nowLabel.width = allLabel.width * progressValue/100.0; contentLabel.text = [NSString stringWithFormat:@"已完成%@,共需%@",timeString,allTimeString]; }else { nowLabel.hidden = YES; progressLabel.text = @"0%"; contentLabel.text = [NSString stringWithFormat:@"已完成0分钟,共需%@",allTimeString]; } } @end