123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //
- // RDSRoomCell.m
- // Temperature
- //
- // Created by RD on 2022/10/31.
- //
- #import "RDSRoomCell.h"
- @interface RDSRoomCell()
- @property (nonatomic, strong) UIView *containerView;
- @property (nonatomic, strong) UIImageView *iconView;
- @property (nonatomic, strong) UILabel *roomNameLabel;
- @property (nonatomic, strong) UILabel *deviceTypeLabel;
- @property (nonatomic, strong) UIView *lineView;
- @property (nonatomic, strong) UIView *pointView;
- @property (nonatomic, strong) UILabel *statusLabel;
- @property (nonatomic, strong) UISwitch *deviceSwitch;
- @end
- @implementation RDSRoomCell
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self configSubviews];
- }
- return self;
- }
- - (void)setModel:(RDSRoomModel *)model {
- _model = model;
- self.roomNameLabel.text = model.name;
- self.iconView.image = [UIImage imageNamed:@"icon_fluorine_main_controller"];
- self.deviceTypeLabel.text = @"主控制器";
- self.deviceSwitch.on = model.power;
- if (model.power) {
- self.statusLabel.text = [NSString stringWithFormat:@"温度%@°C 湿度%@%%", @(model.temperature), @(model.humidity)];
- self.statusLabel.textColor = [UIColor colorWithHexString:@"#14C9C8"];
- self.pointView.backgroundColor = [UIColor colorWithHexString:@"#14C9C8"];
- } else {
- self.statusLabel.text = @"已离线";
- self.statusLabel.textColor = [UIColor colorWithHexString:@"#FAAD14"];
- self.pointView.backgroundColor = [UIColor colorWithHexString:@"#FAAD14"];
- }
- }
- - (void)configSubviews {
- [self.contentView addSubview:self.containerView];
- [self.containerView addSubview:self.iconView];
- [self.containerView addSubview:self.roomNameLabel];
- [self.containerView addSubview:self.deviceTypeLabel];
- [self.containerView addSubview:self.lineView];
- [self.containerView addSubview:self.pointView];
- [self.containerView addSubview:self.statusLabel];
- [self.containerView addSubview:self.deviceSwitch];
-
- [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(UIEdgeInsetsZero);
- }];
-
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(self.containerView).offset(20);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- make.bottom.equalTo(self.containerView).offset(-20);
- }];
-
- [self.deviceSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(48, 24));
- make.centerY.mas_equalTo(0);
- make.right.equalTo(self.containerView).offset(-16);
- }];
-
- [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.iconView.mas_right).offset(12);
- make.top.equalTo(self.containerView).offset(18);
- make.right.equalTo(self.deviceSwitch.mas_left).offset(-12);
- make.height.mas_equalTo(23);
- }];
-
- [self.deviceTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.roomNameLabel);
- make.bottom.equalTo(self.containerView).offset(-18);
- make.height.mas_equalTo(17);
- }];
- [self.deviceTypeLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
-
- [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(1, 8));
- make.centerY.equalTo(self.deviceTypeLabel);
- make.left.equalTo(self.deviceTypeLabel.mas_right).offset(8);
- }];
-
- [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(5, 5));
- make.centerY.equalTo(self.deviceTypeLabel);
- make.left.equalTo(self.lineView.mas_right).offset(8);
- }];
-
- [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.height.equalTo(self.deviceTypeLabel);
- make.left.equalTo(self.pointView.mas_right).offset(5);
- make.right.equalTo(self.roomNameLabel);
- }];
- }
- - (UIView *)containerView {
- if (!_containerView) {
- _containerView = [[UIView alloc] init];
- _containerView.backgroundColor = UIColor.whiteColor;
- _containerView.layer.cornerRadius = 6;
- }
- return _containerView;
- }
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- }
- return _iconView;
- }
- - (UILabel *)roomNameLabel {
- if (!_roomNameLabel) {
- _roomNameLabel = [[UILabel alloc] init];
- _roomNameLabel.font = [UIFont pingFangSCMediumOfSize:16];
- _roomNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
- }
- return _roomNameLabel;
- }
- - (UILabel *)deviceTypeLabel {
- if (!_deviceTypeLabel) {
- _deviceTypeLabel = [[UILabel alloc] init];
- _deviceTypeLabel.font = [UIFont pingFangSCRegularOfSize:12];
- _deviceTypeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
- }
- return _deviceTypeLabel;
- }
- - (UIView *)lineView {
- if (!_lineView) {
- _lineView = [[UIView alloc] init];
- _lineView.backgroundColor = [UIColor colorWithHexString:@"#999999"];
- }
- return _lineView;
- }
- - (UIView *)pointView {
- if (!_pointView) {
- _pointView = [[UIView alloc] init];
- _pointView.layer.cornerRadius = 2.5;
- }
- return _pointView;
- }
- - (UILabel *)statusLabel {
- if (!_statusLabel) {
- _statusLabel = [[UILabel alloc] init];
- _statusLabel.font = [UIFont pingFangSCRegularOfSize:12];
- }
- return _statusLabel;
- }
- - (UISwitch *)deviceSwitch {
- if (!_deviceSwitch) {
- _deviceSwitch = [[UISwitch alloc] init];
- _deviceSwitch.onTintColor = [UIColor colorWithHexString:@"#14C9C8"];
- _deviceSwitch.tintColor = [UIColor colorWithHexString:@"#D9D9D9"];
- }
- return _deviceSwitch;
- }
- @end
|