RDSRoomCell.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // RDSRoomCell.m
  3. // Temperature
  4. //
  5. // Created by RD on 2022/10/31.
  6. //
  7. #import "RDSRoomCell.h"
  8. @interface RDSRoomCell()
  9. @property (nonatomic, strong) UIView *containerView;
  10. @property (nonatomic, strong) UIImageView *iconView;
  11. @property (nonatomic, strong) UILabel *roomNameLabel;
  12. @property (nonatomic, strong) UILabel *deviceTypeLabel;
  13. @property (nonatomic, strong) UIView *lineView;
  14. @property (nonatomic, strong) UIView *pointView;
  15. @property (nonatomic, strong) UILabel *statusLabel;
  16. @property (nonatomic, strong) UISwitch *deviceSwitch;
  17. @end
  18. @implementation RDSRoomCell
  19. - (instancetype)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. [self configSubviews];
  23. }
  24. return self;
  25. }
  26. - (void)setModel:(RDSRoomModel *)model {
  27. _model = model;
  28. self.roomNameLabel.text = model.name;
  29. self.iconView.image = [UIImage imageNamed:@"icon_fluorine_main_controller"];
  30. self.deviceTypeLabel.text = @"主控制器";
  31. self.deviceSwitch.on = model.power;
  32. if (model.power) {
  33. self.statusLabel.text = [NSString stringWithFormat:@"温度%@°C 湿度%@%%", @(model.temperature), @(model.humidity)];
  34. self.statusLabel.textColor = [UIColor colorWithHexString:@"#14C9C8"];
  35. self.pointView.backgroundColor = [UIColor colorWithHexString:@"#14C9C8"];
  36. } else {
  37. self.statusLabel.text = @"已离线";
  38. self.statusLabel.textColor = [UIColor colorWithHexString:@"#FAAD14"];
  39. self.pointView.backgroundColor = [UIColor colorWithHexString:@"#FAAD14"];
  40. }
  41. }
  42. - (void)configSubviews {
  43. [self.contentView addSubview:self.containerView];
  44. [self.containerView addSubview:self.iconView];
  45. [self.containerView addSubview:self.roomNameLabel];
  46. [self.containerView addSubview:self.deviceTypeLabel];
  47. [self.containerView addSubview:self.lineView];
  48. [self.containerView addSubview:self.pointView];
  49. [self.containerView addSubview:self.statusLabel];
  50. [self.containerView addSubview:self.deviceSwitch];
  51. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.edges.mas_equalTo(UIEdgeInsetsZero);
  53. }];
  54. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.top.equalTo(self.containerView).offset(20);
  56. make.size.mas_equalTo(CGSizeMake(40, 40));
  57. make.bottom.equalTo(self.containerView).offset(-20);
  58. }];
  59. [self.deviceSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.size.mas_equalTo(CGSizeMake(48, 24));
  61. make.centerY.mas_equalTo(0);
  62. make.right.equalTo(self.containerView).offset(-16);
  63. }];
  64. [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self.iconView.mas_right).offset(12);
  66. make.top.equalTo(self.containerView).offset(18);
  67. make.right.equalTo(self.deviceSwitch.mas_left).offset(-12);
  68. make.height.mas_equalTo(23);
  69. }];
  70. [self.deviceTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(self.roomNameLabel);
  72. make.bottom.equalTo(self.containerView).offset(-18);
  73. make.height.mas_equalTo(17);
  74. }];
  75. [self.deviceTypeLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  76. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.size.mas_equalTo(CGSizeMake(1, 8));
  78. make.centerY.equalTo(self.deviceTypeLabel);
  79. make.left.equalTo(self.deviceTypeLabel.mas_right).offset(8);
  80. }];
  81. [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.size.mas_equalTo(CGSizeMake(5, 5));
  83. make.centerY.equalTo(self.deviceTypeLabel);
  84. make.left.equalTo(self.lineView.mas_right).offset(8);
  85. }];
  86. [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.bottom.height.equalTo(self.deviceTypeLabel);
  88. make.left.equalTo(self.pointView.mas_right).offset(5);
  89. make.right.equalTo(self.roomNameLabel);
  90. }];
  91. }
  92. - (UIView *)containerView {
  93. if (!_containerView) {
  94. _containerView = [[UIView alloc] init];
  95. _containerView.backgroundColor = UIColor.whiteColor;
  96. _containerView.layer.cornerRadius = 6;
  97. }
  98. return _containerView;
  99. }
  100. - (UIImageView *)iconView {
  101. if (!_iconView) {
  102. _iconView = [[UIImageView alloc] init];
  103. }
  104. return _iconView;
  105. }
  106. - (UILabel *)roomNameLabel {
  107. if (!_roomNameLabel) {
  108. _roomNameLabel = [[UILabel alloc] init];
  109. _roomNameLabel.font = [UIFont pingFangSCMediumOfSize:16];
  110. _roomNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  111. }
  112. return _roomNameLabel;
  113. }
  114. - (UILabel *)deviceTypeLabel {
  115. if (!_deviceTypeLabel) {
  116. _deviceTypeLabel = [[UILabel alloc] init];
  117. _deviceTypeLabel.font = [UIFont pingFangSCRegularOfSize:12];
  118. _deviceTypeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  119. }
  120. return _deviceTypeLabel;
  121. }
  122. - (UIView *)lineView {
  123. if (!_lineView) {
  124. _lineView = [[UIView alloc] init];
  125. _lineView.backgroundColor = [UIColor colorWithHexString:@"#999999"];
  126. }
  127. return _lineView;
  128. }
  129. - (UIView *)pointView {
  130. if (!_pointView) {
  131. _pointView = [[UIView alloc] init];
  132. _pointView.layer.cornerRadius = 2.5;
  133. }
  134. return _pointView;
  135. }
  136. - (UILabel *)statusLabel {
  137. if (!_statusLabel) {
  138. _statusLabel = [[UILabel alloc] init];
  139. _statusLabel.font = [UIFont pingFangSCRegularOfSize:12];
  140. }
  141. return _statusLabel;
  142. }
  143. - (UISwitch *)deviceSwitch {
  144. if (!_deviceSwitch) {
  145. _deviceSwitch = [[UISwitch alloc] init];
  146. _deviceSwitch.onTintColor = [UIColor colorWithHexString:@"#14C9C8"];
  147. _deviceSwitch.tintColor = [UIColor colorWithHexString:@"#D9D9D9"];
  148. }
  149. return _deviceSwitch;
  150. }
  151. @end