YXLeftTableViewCell.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // YXLeftTableViewCell.m
  3. // Temperature
  4. //
  5. // Created by z on 2025/1/17.
  6. //
  7. #import "YXLeftTableViewCell.h"
  8. @interface YXLeftTableViewCell ()
  9. @property (nonatomic, strong) UIView *colorView;
  10. @end
  11. @implementation YXLeftTableViewCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. // Initialization code
  15. }
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  17. {
  18. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
  19. {
  20. self.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. self.titleLabel = [[UILabel alloc] init];
  23. self.titleLabel.numberOfLines = 0;
  24. self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
  25. self.titleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
  26. self.titleLabel.highlightedTextColor = [UIColor colorWithHexString:@"#1E1E1E"];
  27. [self.contentView addSubview:self.titleLabel];
  28. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.centerY.equalTo(self.mas_centerY);
  30. make.left.equalTo(@10);
  31. make.right.equalTo(@10);
  32. make.height.equalTo(@30);
  33. }];
  34. self.colorView = [[UIView alloc] init];
  35. self.colorView.backgroundColor = [UIColor colorWithHexString:@"#267AFF"];
  36. [self.contentView addSubview:self.colorView];
  37. [self.colorView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.centerY.equalTo(self.mas_centerY);
  39. make.left.equalTo(@3);
  40. make.width.equalTo(@3);
  41. make.height.equalTo(@15);
  42. }];
  43. self.colorView.layer.cornerRadius = 1.5;
  44. }
  45. return self;
  46. }
  47. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  48. {
  49. [super setSelected:selected animated:animated];
  50. // Configure the view for the selected state
  51. self.contentView.backgroundColor = selected ? [UIColor whiteColor] : [UIColor colorWithHexString:@"#F9F9F9"];
  52. self.highlighted = selected;
  53. self.titleLabel.highlighted = selected;
  54. self.titleLabel.font = selected ? [UIFont boldSystemFontOfSize:14] : [UIFont boldSystemFontOfSize:13];
  55. self.colorView.hidden = !selected;
  56. }
  57. @end