RDSRoomCell.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.pointView.backgroundColor = [UIColor colorWithHexString:@"#14C9C8"];
  32. self.statusLabel.textColor = [UIColor colorWithHexString:@"#14C9C8"];
  33. self.statusLabel.text = @"温度24°C 湿度38%";
  34. }
  35. - (void)configSubviews {
  36. [self.contentView addSubview:self.containerView];
  37. [self.containerView addSubview:self.iconView];
  38. [self.containerView addSubview:self.roomNameLabel];
  39. [self.containerView addSubview:self.deviceTypeLabel];
  40. [self.containerView addSubview:self.lineView];
  41. [self.containerView addSubview:self.pointView];
  42. [self.containerView addSubview:self.statusLabel];
  43. [self.containerView addSubview:self.deviceSwitch];
  44. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.edges.mas_equalTo(UIEdgeInsetsZero);
  46. }];
  47. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.top.equalTo(self.containerView).offset(20);
  49. make.size.mas_equalTo(CGSizeMake(40, 40));
  50. make.bottom.equalTo(self.containerView).offset(-20);
  51. }];
  52. [self.deviceSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.size.mas_equalTo(CGSizeMake(48, 24));
  54. make.centerY.mas_equalTo(0);
  55. make.right.equalTo(self.containerView).offset(-16);
  56. }];
  57. [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.equalTo(self.iconView.mas_right).offset(12);
  59. make.top.equalTo(self.containerView).offset(18);
  60. make.right.equalTo(self.deviceSwitch.mas_left).offset(-12);
  61. make.height.mas_equalTo(23);
  62. }];
  63. [self.deviceTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.equalTo(self.roomNameLabel);
  65. make.bottom.equalTo(self.containerView).offset(-18);
  66. make.height.mas_equalTo(17);
  67. }];
  68. [self.deviceTypeLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
  69. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.size.mas_equalTo(CGSizeMake(1, 8));
  71. make.centerY.equalTo(self.deviceTypeLabel);
  72. make.left.equalTo(self.deviceTypeLabel.mas_right).offset(8);
  73. }];
  74. [self.pointView mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.size.mas_equalTo(CGSizeMake(5, 5));
  76. make.centerY.equalTo(self.deviceTypeLabel);
  77. make.left.equalTo(self.lineView.mas_right).offset(8);
  78. }];
  79. [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.bottom.height.equalTo(self.deviceTypeLabel);
  81. make.left.equalTo(self.pointView.mas_right).offset(5);
  82. make.right.equalTo(self.roomNameLabel);
  83. }];
  84. }
  85. - (UIView *)containerView {
  86. if (!_containerView) {
  87. _containerView = [[UIView alloc] init];
  88. _containerView.backgroundColor = UIColor.whiteColor;
  89. _containerView.layer.cornerRadius = 6;
  90. }
  91. return _containerView;
  92. }
  93. - (UIImageView *)iconView {
  94. if (!_iconView) {
  95. _iconView = [[UIImageView alloc] init];
  96. }
  97. return _iconView;
  98. }
  99. - (UILabel *)roomNameLabel {
  100. if (!_roomNameLabel) {
  101. _roomNameLabel = [[UILabel alloc] init];
  102. _roomNameLabel.font = [UIFont pingFangSCMediumOfSize:16];
  103. _roomNameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
  104. }
  105. return _roomNameLabel;
  106. }
  107. - (UILabel *)deviceTypeLabel {
  108. if (!_deviceTypeLabel) {
  109. _deviceTypeLabel = [[UILabel alloc] init];
  110. _deviceTypeLabel.font = [UIFont pingFangSCRegularOfSize:12];
  111. _deviceTypeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  112. }
  113. return _deviceTypeLabel;
  114. }
  115. - (UIView *)lineView {
  116. if (!_lineView) {
  117. _lineView = [[UIView alloc] init];
  118. _lineView.backgroundColor = [UIColor colorWithHexString:@"#999999"];
  119. }
  120. return _lineView;
  121. }
  122. - (UIView *)pointView {
  123. if (!_pointView) {
  124. _pointView = [[UIView alloc] init];
  125. _pointView.layer.cornerRadius = 2.5;
  126. }
  127. return _pointView;
  128. }
  129. - (UILabel *)statusLabel {
  130. if (!_statusLabel) {
  131. _statusLabel = [[UILabel alloc] init];
  132. _statusLabel.font = [UIFont pingFangSCRegularOfSize:12];
  133. }
  134. return _statusLabel;
  135. }
  136. - (UISwitch *)deviceSwitch {
  137. if (!_deviceSwitch) {
  138. _deviceSwitch = [[UISwitch alloc] init];
  139. _deviceSwitch.onTintColor = [UIColor colorWithHexString:@"#14C9C8"];
  140. _deviceSwitch.tintColor = [UIColor colorWithHexString:@"#D9D9D9"];
  141. }
  142. return _deviceSwitch;
  143. }
  144. @end