// // DetailItemCell.m // WeSugar // // Created by 单军华 on 2018/7/6. // Copyright © 2018年 单军华. All rights reserved. // #import "DetailItemCell.h" #import "GradientProgressView.h" @interface DetailItemCell () /** 参数名字 */ @property (nonatomic, strong) UILabel * NameLabel; /** 进度条 */ @property (nonatomic, strong) GradientProgressView * pPregressView; /** 当前值 */ @property (nonatomic, strong) UILabel * currentValueLabel; /** 单位 */ @property (nonatomic, strong) UILabel * UnitLabel; @end @implementation DetailItemCell - (GradientProgressView *)pPregressView { if (!_pPregressView) { _pPregressView = [[GradientProgressView alloc] initWithFrame:CGRectMake(0, 0, 300, 20)]; _pPregressView.colorArr = @[(id)HexColor(0x00a445).CGColor, (id)HexColor(0x23d9a0).CGColor, (id)HexColor(0x00ffde).CGColor]; _pPregressView.progress = 0.00; _pPregressView.bgProgressColor = RgbColor(24, 70, 149); [self.contentView addSubview:_pPregressView]; } return _pPregressView; } - (UILabel *)NameLabel { if (!_NameLabel) { _NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 60)]; _NameLabel.font = AdaptedFontSize(10); _NameLabel.textColor = [UIColor whiteColor]; _NameLabel.textAlignment = NSTextAlignmentRight; [self.contentView addSubview:_NameLabel]; } return _NameLabel; } - (UILabel *)currentValueLabel { if (!_currentValueLabel) { _currentValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 60)]; _currentValueLabel.font = AdaptedFontSize(10); _currentValueLabel.textColor = [UIColor whiteColor]; _currentValueLabel.textAlignment = NSTextAlignmentLeft; [self.contentView addSubview:_currentValueLabel]; } return _currentValueLabel; } - (UILabel *)UnitLabel { if (!_UnitLabel) { _UnitLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-20, 60)]; _UnitLabel.font = AdaptedFontSize(10); _UnitLabel.textColor = [UIColor whiteColor]; _UnitLabel.textAlignment = NSTextAlignmentLeft; [self.contentView addSubview:_UnitLabel]; } return _UnitLabel; } // 设置UI布局 - (void)layoutSubviews { [super layoutSubviews]; self.NameLabel.frame = CGRectMake(AdaptedWidth(10), AdaptedHeight(7), AdaptedWidth(50), AdaptedHeight(14)); self.pPregressView.frame = CGRectMake(AdaptedWidth(10+50+10), AdaptedHeight(7),AdaptedWidth(150), AdaptedHeight(14)); self.currentValueLabel.frame = CGRectMake(AdaptedWidth(10+50+10+150+10), AdaptedHeight(7), AdaptedWidth(40), AdaptedHeight(14)); self.UnitLabel.frame = CGRectMake(AdaptedWidth(10+50+10+150+10+40+5), AdaptedHeight(7), AdaptedWidth(60), AdaptedHeight(14)); } + (instancetype)topicCellWithTableView:(UITableView *)tableView { DetailItemCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class])]; if (cell == nil) { cell = [[DetailItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([self class])]; cell.backgroundColor = [UIColor clearColor]; } return cell; } - (void)setDetailViewModel:(DetailModel *)detailViewModel { _detailViewModel = detailViewModel; // Model self.NameLabel.text = _detailViewModel.name; self.UnitLabel.text = [NSString stringWithFormat:@"(%@)",detailViewModel.unit]; if([StringUtil isPureFloat:detailViewModel.value] && ![StringUtil isPureInt:detailViewModel.value]) { detailViewModel.value = [NSString stringWithFormat:@"%.2f",[detailViewModel.value floatValue]]; } self.currentValueLabel.text = detailViewModel.value; //e17 if([_detailViewModel.sensor_key isEqualToString:@"e17"]) { _NameLabel.font = AdaptedFontSize(9); } else { _NameLabel.font = AdaptedFontSize(10); } CGFloat progress = 0.0; if([detailViewModel.upper floatValue] != 0) { progress = ([detailViewModel.value floatValue]/[detailViewModel.upper floatValue]); } self.pPregressView.progress = progress; } // 第一次打开设置一次 - (void)setupTopicCellUIOnce { // self.contentTextLabel.font = AdaptedFontSize(16); // // self.headerImageView.layer.cornerRadius = 25; // self.headerImageView.layer.masksToBounds = YES; self.selectionStyle = UITableViewCellSelectionStyleNone; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setupTopicCellUIOnce]; } return self; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end