// // TrainSituationCell.m // LN_School // // Created by 张嵘 on 2019/7/31. // Copyright © 2019 Danson. All rights reserved. // #import "TrainSituationCell.h" #import "TrainSituationModel.h" @interface TrainSituationCell () @property (nonatomic, readwrite, strong) UIImageView *headImageView; @property (nonatomic, readwrite, strong) UILabel *nameLabel; @property (nonatomic, readwrite, strong) UILabel *carTypeLabel; @property (nonatomic, readwrite, strong) UILabel *totalHoursLabel; @property (nonatomic, readwrite, strong) UILabel *finishedHoursLabel; @property (nonatomic, readwrite, strong) UIImageView *arrowImageView; @property (nonatomic, readwrite, strong) UIImageView *bottomLineView; @end @implementation TrainSituationCell #pragma mark - Life Cycle - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.contentView.backgroundColor = UIColor.whiteColor; [self.contentView addSubview:self.headImageView]; [self.contentView addSubview:self.nameLabel]; [self.contentView addSubview:self.carTypeLabel]; [self.contentView addSubview:self.totalHoursLabel]; [self.contentView addSubview:self.finishedHoursLabel]; [self.contentView addSubview:self.arrowImageView]; [self.contentView addSubview:self.bottomLineView]; } __weak typeof(self) weakS = self; [self addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) { [weakS clickSelf]; }]; return self; } - (void)layoutSubviews { [super layoutSubviews]; CGFloat width = self.bounds.size.width - 16 - 16 - 16; [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.contentView); make.left.mas_equalTo(self.contentView).mas_offset(16); make.size.mas_equalTo(CGSizeMake(width * 0.15, width * 0.15)); }]; [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView).mas_offset(8); make.left.mas_equalTo(_headImageView.mas_right).mas_offset(16); make.size.mas_equalTo(CGSizeMake(width * 0.425, self.bounds.size.height * 0.4)); }]; [_carTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(_nameLabel); make.bottom.mas_equalTo(self.contentView).mas_offset(-8); make.size.mas_equalTo(_nameLabel); }]; [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.contentView); make.right.mas_equalTo(self.contentView).mas_offset(-16); make.size.mas_equalTo(CGSizeMake(width * 0.025, (width * 0.025) * (39.0 / 21.0))); }]; [_totalHoursLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(_nameLabel); make.right.mas_equalTo(_arrowImageView.mas_left); make.size.mas_equalTo(CGSizeMake(width * 0.4, self.bounds.size.height * 0.4)); }]; [_finishedHoursLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(_carTypeLabel); make.right.mas_equalTo(_arrowImageView.mas_left); make.size.mas_equalTo(_totalHoursLabel); }]; [_bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_offset(16); make.right.mas_offset(-16); make.bottom.mas_offset(0); make.height.mas_equalTo(1); }]; } #pragma mark - HDUpdateUIProtocol - (void)updateCellUI:(__kindof HDCellModel *)model { TrainSituationModel *trainSituationModel = model.orgData; self.headImageView.image = [UIImage imageNamed:trainSituationModel.imageName]; self.nameLabel.text = [NSString stringWithFormat:@"姓名:%@",trainSituationModel.name]; self.carTypeLabel.text = [NSString stringWithFormat:@"车型:%@",trainSituationModel.carType]; self.totalHoursLabel.text = [NSString stringWithFormat:@"培训总学时:%@",trainSituationModel.totalHours]; self.finishedHoursLabel.text = [NSString stringWithFormat:@"已完成学时:%@",trainSituationModel.finishedHours]; } #pragma mark - Private Functions - (void)clickSelf { self.callback(self.hdModel); } #pragma mark - Lazy Load - (UIImageView *)headImageView { if (!_headImageView) { _headImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HeaderPlacehold"]]; } return _headImageView; } - (UILabel *)nameLabel { if (!_nameLabel) { _nameLabel = [[UILabel alloc] init]; _nameLabel.textAlignment = NSTextAlignmentLeft; _nameLabel.textColor = RQTitleTextColor; _nameLabel.numberOfLines = 0; _nameLabel.font = [UIFont systemFontOfSize:15]; } return _nameLabel; } - (UILabel *)carTypeLabel { if (!_carTypeLabel) { _carTypeLabel = [[UILabel alloc] init]; _carTypeLabel.textAlignment = NSTextAlignmentLeft; _carTypeLabel.textColor = RQTitleTextColor; _carTypeLabel.numberOfLines = 0; _carTypeLabel.font = [UIFont systemFontOfSize:15]; } return _carTypeLabel; } - (UILabel *)totalHoursLabel { if (!_totalHoursLabel) { _totalHoursLabel = [[UILabel alloc] init]; _totalHoursLabel.textAlignment = NSTextAlignmentLeft; _totalHoursLabel.textColor = RQTitleTextColor; _totalHoursLabel.numberOfLines = 0; _totalHoursLabel.font = [UIFont systemFontOfSize:15]; } return _totalHoursLabel; } - (UILabel *)finishedHoursLabel { if (!_finishedHoursLabel) { _finishedHoursLabel = [[UILabel alloc] init]; _finishedHoursLabel.textAlignment = NSTextAlignmentLeft; _finishedHoursLabel.textColor = RQTitleTextColor; _finishedHoursLabel.numberOfLines = 0; _finishedHoursLabel.font = [UIFont systemFontOfSize:15]; } return _finishedHoursLabel; } - (UIImageView *)arrowImageView { if (!_arrowImageView) { _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Arrow"]]; } return _arrowImageView; } - (UIImageView *)bottomLineView { if (!_bottomLineView) { _bottomLineView = [[UIImageView alloc] init]; _bottomLineView.backgroundColor = RQBackGroundColor; } return _bottomLineView; } @end