单军华
2018-07-11 7b02207537d35bfa1714bf8beafc921f717d100a
screendisplay/screendisplay/Classes/??/View/DetailItemCell.m
New file
@@ -0,0 +1,161 @@
//
//  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];
    self.currentValueLabel.text = detailViewModel.value;
    CGFloat progress = (([detailViewModel.value floatValue]-[detailViewModel.lower floatValue])/([detailViewModel.upper floatValue] -[detailViewModel.lower 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