单军华
2018-07-12 3e8437ae559487362fae3525beb79c534c213a51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
//  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