TrainingSituationCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // TrainingSituationCell.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2019/7/18.
  6. // Copyright © 2019 Danson. All rights reserved.
  7. //
  8. #import "TrainingSituationCell.h"
  9. #import "TrainingSituationModel.h"
  10. @interface TrainingSituationCell ()
  11. @property (nonatomic, readwrite, strong) UIImageView *headImageView;
  12. @property (nonatomic, readwrite, strong) UILabel *nameLabel;
  13. @property (nonatomic, readwrite, strong) UILabel *carTypeLabel;
  14. @property (nonatomic, readwrite, strong) UILabel *totalHoursLabel;
  15. @property (nonatomic, readwrite, strong) UILabel *finishedHoursLabel;
  16. @property (nonatomic, readwrite, strong) UIImageView *arrowImageView;
  17. @property (nonatomic, readwrite, strong) UIImageView *bottomLineView;
  18. @end
  19. @implementation TrainingSituationCell
  20. #pragma mark - Life Cycle
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. self.contentView.backgroundColor = UIColor.whiteColor;
  25. [self.contentView addSubview:self.headImageView];
  26. [self.contentView addSubview:self.nameLabel];
  27. [self.contentView addSubview:self.carTypeLabel];
  28. [self.contentView addSubview:self.totalHoursLabel];
  29. [self.contentView addSubview:self.finishedHoursLabel];
  30. [self.contentView addSubview:self.arrowImageView];
  31. [self.contentView addSubview:self.bottomLineView];
  32. }
  33. __weak typeof(self) weakS = self;
  34. [self addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
  35. [weakS clickSelf];
  36. }];
  37. return self;
  38. }
  39. - (void)layoutSubviews {
  40. [super layoutSubviews];
  41. CGFloat width = self.bounds.size.width - 16 - 16 - 16;
  42. [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerY.mas_equalTo(self.contentView);
  44. make.left.mas_equalTo(self.contentView).mas_offset(16);
  45. make.size.mas_equalTo(CGSizeMake(width * 0.15, width * 0.15));
  46. }];
  47. [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.mas_equalTo(self.contentView).mas_offset(8);
  49. make.left.mas_equalTo(_headImageView.mas_right).mas_offset(16);
  50. make.size.mas_equalTo(CGSizeMake(width * 0.425, self.bounds.size.height * 0.4));
  51. }];
  52. [_carTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(_nameLabel);
  54. make.bottom.mas_equalTo(self.contentView).mas_offset(-8);
  55. make.size.mas_equalTo(_nameLabel);
  56. }];
  57. [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.mas_equalTo(self.contentView);
  59. make.right.mas_equalTo(self.contentView).mas_offset(-16);
  60. make.size.mas_equalTo(CGSizeMake(width * 0.025, (width * 0.025) * (39.0 / 21.0)));
  61. }];
  62. [_totalHoursLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.mas_equalTo(_nameLabel);
  64. make.right.mas_equalTo(_arrowImageView.mas_left);
  65. make.size.mas_equalTo(CGSizeMake(width * 0.4, self.bounds.size.height * 0.4));
  66. }];
  67. [_finishedHoursLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.bottom.mas_equalTo(_carTypeLabel);
  69. make.right.mas_equalTo(_arrowImageView.mas_left);
  70. make.size.mas_equalTo(_totalHoursLabel);
  71. }];
  72. [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_offset(16);
  74. make.right.mas_offset(-16);
  75. make.bottom.mas_offset(0);
  76. make.height.mas_equalTo(1);
  77. }];
  78. }
  79. #pragma mark - HDUpdateUIProtocol
  80. - (void)updateCellUI:(__kindof HDCellModel *)model {
  81. TrainingSituationModel *trainingSituationModel = model.orgData;
  82. self.headImageView.image = [UIImage imageNamed:trainingSituationModel.imageName];
  83. self.nameLabel.text = [NSString stringWithFormat:@"姓名:%@",trainingSituationModel.name];
  84. self.carTypeLabel.text = [NSString stringWithFormat:@"车型:%@",trainingSituationModel.carType];
  85. self.totalHoursLabel.text = [NSString stringWithFormat:@"培训总学时:%@",trainingSituationModel.totalHours];
  86. self.finishedHoursLabel.text = [NSString stringWithFormat:@"已完成学时:%@",trainingSituationModel.finishedHours];
  87. }
  88. #pragma mark - Private Functions
  89. - (void)clickSelf {
  90. self.callback(self.hdModel);
  91. }
  92. #pragma mark - Lazy Load
  93. - (UIImageView *)headImageView {
  94. if (!_headImageView) {
  95. _headImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HeaderPlacehold"]];
  96. }
  97. return _headImageView;
  98. }
  99. - (UILabel *)nameLabel {
  100. if (!_nameLabel) {
  101. _nameLabel = [[UILabel alloc] init];
  102. _nameLabel.textAlignment = NSTextAlignmentLeft;
  103. _nameLabel.textColor = RQTitleTextColor;
  104. _nameLabel.numberOfLines = 0;
  105. _nameLabel.font = [UIFont systemFontOfSize:15];
  106. }
  107. return _nameLabel;
  108. }
  109. - (UILabel *)carTypeLabel {
  110. if (!_carTypeLabel) {
  111. _carTypeLabel = [[UILabel alloc] init];
  112. _carTypeLabel.textAlignment = NSTextAlignmentLeft;
  113. _carTypeLabel.textColor = RQTitleTextColor;
  114. _carTypeLabel.numberOfLines = 0;
  115. _carTypeLabel.font = [UIFont systemFontOfSize:15];
  116. }
  117. return _carTypeLabel;
  118. }
  119. - (UILabel *)totalHoursLabel {
  120. if (!_totalHoursLabel) {
  121. _totalHoursLabel = [[UILabel alloc] init];
  122. _totalHoursLabel.textAlignment = NSTextAlignmentLeft;
  123. _totalHoursLabel.textColor = RQTitleTextColor;
  124. _totalHoursLabel.numberOfLines = 0;
  125. _totalHoursLabel.font = [UIFont systemFontOfSize:15];
  126. }
  127. return _totalHoursLabel;
  128. }
  129. - (UILabel *)finishedHoursLabel {
  130. if (!_finishedHoursLabel) {
  131. _finishedHoursLabel = [[UILabel alloc] init];
  132. _finishedHoursLabel.textAlignment = NSTextAlignmentLeft;
  133. _finishedHoursLabel.textColor = RQTitleTextColor;
  134. _finishedHoursLabel.numberOfLines = 0;
  135. _finishedHoursLabel.font = [UIFont systemFontOfSize:15];
  136. }
  137. return _finishedHoursLabel;
  138. }
  139. - (UIImageView *)arrowImageView {
  140. if (!_arrowImageView) {
  141. _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Arrow"]];
  142. }
  143. return _arrowImageView;
  144. }
  145. - (UIImageView *)bottomLineView {
  146. if (!_bottomLineView) {
  147. _bottomLineView = [[UIImageView alloc] init];
  148. _bottomLineView.backgroundColor = RQBackGroundColor;
  149. }
  150. return _bottomLineView;
  151. }
  152. @end