123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // TrainInfoTableViewCell.m
- // jiaPei
- //
- // Created by apple on 2017/2/23.
- // Copyright © 2017年 JCZ. All rights reserved.
- //
- #import "TrainInfoTableViewCell.h"
- @implementation TrainInfoTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- }
- + (TrainInfoTableViewCell*)cellForTabelView:(UITableView*)tableView
- {
- TrainInfoTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"trainInfoTableViewCell"];
- if (!cell) {
- cell = [[TrainInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"trainInfoTableViewCell"];
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.backgroundColor = backGroundColor;
- }
- return cell;
- }
- -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.backgroundColor = backGroundColor;
- CGFloat x,y,w,h;
- x = 20;
- y = 10;
- w = 50;
- h = 25;
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:@"" Font:FontTitle TextColor:kTitleColor];
- [self addSubview:label];
- titleLabel = label;
-
- x += w + 5;
- y += 5;
- w = kSize.width - 2*x;
- 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 = 60;
- h = 25;
- label = [[UILabel alloc] setxywh];
- [label setText:@"" Font:FontTitle TextColor:kTitleColor];
- [self addSubview:label];
- progressLabel = label;
-
- x = 65;
- y += h + 10;
- w = kSize.width - x;
- h = 25;
- label = [[UILabel alloc] setxywh];
- [label setText:@"" Font:FontTitle TextColor:kTitleColor];
- [self addSubview:label];
- contentLabel = label;
-
- x = 65;
- y += h + 5;
- w = kSize.width - x;
- h = 25;
- UILabel *mileage_label = [[UILabel alloc] setxywh];
- [mileage_label setText:@"" Font:FontTitle TextColor:kTitleColor];
- [self addSubview:mileage_label];
- self.mileage_label = mileage_label;
- }
- return self;
- }
- - (void)setDataArray:(NSMutableArray *)dataArray {
- _dataArray = dataArray;
-
- //防止除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];
- } else if (allHour != 0 && allMin == 0) {
- allTimeString = [NSString stringWithFormat:@"%d%@",(int)allHour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时")];
- }
-
- if (dataArray.count > 0) {
- titleLabel.text = _titleString;//虽然可以用dic来判断 这样比较省事
- NSString *totalTimeString = [self getTotalTime:dataArray];
- contentLabel.text = [NSString stringWithFormat:@"已完成%@,共需%@",totalTimeString,allTimeString];
-
- } else {
- nowLabel.hidden = YES;
- titleLabel.text = _titleString;
- progressLabel.text = @"0%";
- contentLabel.text = [NSString stringWithFormat:@"已完成0分钟,共需%@",allTimeString];
- }
- }
- - (NSString *)getTotalTime:(NSMutableArray *)array {
- if ([array count] < 1) {
- return @"0分钟";
- }
- int time = 0;
- for (NSDictionary *dic in array) {
- time += [dic[@"CRI_DURATION"] intValue];//CRI_VAILD_TIME
- }
- int hour = time/(_RATIONKS? : 60);
- int min = time%(_RATIONKS? : 60);
-
- NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),min];
- if (hour == 0) {
- timeString = [NSString stringWithFormat:@"%d分钟",min];
- }
-
- //在这个地方给进度条赋值
- CGFloat progressValue = (_allNeedTime == 0)? 0.f : time*1.0/_allNeedTime*100.f;
- if (time >= _allNeedTime) {
- progressLabel.text = @"100%";
- } else {
- NSString *progressValueString = [NSString stringWithFormat:@"%f",progressValue];
- progressLabel.text = [NSString stringWithFormat:@"%@%%",[progressValueString componentsSeparatedByString:@"."].firstObject];
- }
- nowLabel.hidden = NO;
- if (progressValue > 100.0) {
- nowLabel.width = allLabel.width;
- } else {
- nowLabel.width = allLabel.width * progressValue/100.0;
- }
- return timeString;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- @end
|