TrainInfoTableViewCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // TrainInfoTableViewCell.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/2/23.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "TrainInfoTableViewCell.h"
  9. @implementation TrainInfoTableViewCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. }
  13. + (TrainInfoTableViewCell*)cellForTabelView:(UITableView*)tableView
  14. {
  15. TrainInfoTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"trainInfoTableViewCell"];
  16. if (!cell) {
  17. cell = [[TrainInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"trainInfoTableViewCell"];
  18. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  19. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  20. }
  21. return cell;
  22. }
  23. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  24. {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. CGFloat x,y,w,h;
  28. x = 20;
  29. y = 10;
  30. w = 40;
  31. h = 20;
  32. UILabel *label = [[UILabel alloc] setxywh];
  33. [label setText:@"" Font:NormalFont TextColor:kTitleColor];
  34. [self addSubview:label];
  35. label.layer.borderWidth = 0.5;
  36. label.textAlignment = NSTextAlignmentCenter;
  37. label.layer.cornerRadius = 3;
  38. titleLabel = label;
  39. x += w + 5;
  40. y += 2.5;
  41. w = kSize.width - 2*x;
  42. h = 15;
  43. label = [[UILabel alloc] setxywh];
  44. label.backgroundColor = KlineColor;
  45. label.layer.masksToBounds = YES;
  46. label.layer.cornerRadius = 7;
  47. [self addSubview:label];
  48. allLabel = label;
  49. label = [[UILabel alloc] setxywh];
  50. label.layer.masksToBounds = YES;
  51. label.layer.cornerRadius = 7;
  52. [self addSubview:label];
  53. label.hidden = YES;
  54. nowLabel = label;
  55. x += w;
  56. y -= 5;
  57. w = 40;
  58. h = 25;
  59. label = [[UILabel alloc] setxywh];
  60. [label setText:@"" Font:FontTitle TextColor:kTitleColor];
  61. [self addSubview:label];
  62. progressLabel = label;
  63. progressLabel.adjustsFontSizeToFitWidth = YES;
  64. x = 65;
  65. y += h + 10;
  66. w = kSize.width - x;
  67. h = 25;
  68. label = [[UILabel alloc] setxywh];
  69. [label setText:@"" Font:FontTitle TextColor:kTitleColor];
  70. [self addSubview:label];
  71. contentLabel = label;
  72. _checkImg = [UIButton buttonWithType:UIButtonTypeCustom];
  73. _checkImg.multipleTouchEnabled = NO;
  74. _checkImg.userInteractionEnabled = NO;
  75. _checkImg.frame = CGRectMake(kScreenWidth/2.0 - 40, 0, 80, 80);
  76. [_checkImg setImage:[UIImage imageNamed:@"unCheck"] forState:UIControlStateNormal];
  77. [_checkImg setImage:[UIImage imageNamed:@"hasCheck"] forState:UIControlStateSelected];
  78. [self addSubview:_checkImg];
  79. }
  80. return self;
  81. }
  82. -(void)setTitleString:(NSString *)titleString{
  83. _titleString = titleString;
  84. titleLabel.text = titleString;
  85. if ([titleString isEqualToString:@"理论"]) {
  86. titleLabel.textColor = RGB_COLOR(40, 152, 255);
  87. }else if ([titleString isEqualToString:@"模拟"]){
  88. titleLabel.textColor = RGB_COLOR(238, 133, 7);
  89. }else if ([titleString isEqualToString:@"实操"]){
  90. titleLabel.textColor = [UIColor darkGrayColor];
  91. }
  92. titleLabel.layer.borderColor = titleLabel.textColor.CGColor;
  93. nowLabel.backgroundColor = titleLabel.textColor;
  94. }
  95. -(void)setDataArray:(NSMutableArray *)dataArray
  96. {
  97. _dataArray = dataArray;
  98. if (dataArray.count > 0) {
  99. NSString *totalTimeString = [self getTotalTime:dataArray];
  100. contentLabel.text = [NSString stringWithFormat:@"已完成%@,共需%d小时",totalTimeString,(int)_allNeedTime/60];
  101. }else{
  102. nowLabel.hidden = YES;
  103. progressLabel.text = @"0%";
  104. contentLabel.text = [NSString stringWithFormat:@"已完成0分钟,共需%d小时",(int)_allNeedTime/60];
  105. }
  106. }
  107. -(NSString *)getTotalTime:(NSMutableArray *)array
  108. {
  109. if ([array count] < 1)
  110. {
  111. return @"0分钟";
  112. }
  113. int time = 0;
  114. for (NSDictionary *dic in array)
  115. {
  116. //二次审核结果 0审核通过 1审核不通过 2待审核
  117. if (![dic[@"CRI_SECOND_AUDIT_RESULT"] isEqualToString:@"1"]) {
  118. time += [dic[@"CRI_VAILD_TIME"] intValue];
  119. }
  120. }
  121. int hour = time/60;
  122. int min = time%60;
  123. NSString *timeString = [NSString stringWithFormat:@"%d小时%d分钟",hour,min];
  124. if (hour == 0)
  125. {
  126. timeString = [NSString stringWithFormat:@"%d分钟",min];
  127. }
  128. //在这个地方给进度条赋值
  129. CGFloat progressValue = time*1.0/_allNeedTime*100;
  130. progressLabel.text = [NSString stringWithFormat:@"%.0f%%",progressValue];
  131. nowLabel.hidden = NO;
  132. CGFloat percent = progressValue/100.0 > 1 ? 1 :progressValue/100.0;
  133. nowLabel.width = allLabel.width * percent;
  134. return timeString;
  135. }
  136. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  137. [super setSelected:selected animated:animated];
  138. }
  139. @end