XYMyVoiceRoomListTableViewCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // XYMyVoiceRoomListTableViewCell.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/7/7.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYMyVoiceRoomListTableViewCell.h"
  9. #import "XYMyVoiceRoomListModel.h"
  10. @interface XYMyVoiceRoomListTableViewCell ()
  11. @property (nonatomic, strong) UIImageView *headImageView;
  12. @property (nonatomic, strong) UILabel *categoryNameLabel;
  13. @property (nonatomic, strong) UILabel *roomRoleLabel;
  14. @property (nonatomic, strong) UILabel *roomNameLabel;
  15. @property (nonatomic, strong) UILabel *roomHeatLabel;
  16. @property (nonatomic, strong) UIView *line;
  17. @end
  18. @implementation XYMyVoiceRoomListTableViewCell
  19. #pragma mark — Public
  20. + (instancetype)cellWithTableView:(UITableView *)tableView
  21. {
  22. static NSString *ID = @"XYMyVoiceRoomListTableViewCell";
  23. XYMyVoiceRoomListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  24. if (cell == nil) {
  25. cell = [[XYMyVoiceRoomListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
  26. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  27. }
  28. return cell;
  29. }
  30. - (void)configureModel:(XYMyVoiceRoomListModel *)model
  31. {
  32. [self.headImageView sd_setImageWithURL:UrlForString(model.roomCover) placeholderImage:placeholderImage()];
  33. self.categoryNameLabel.text = model.categoryName;
  34. CGFloat categoryNameWidht = [self.categoryNameLabel sizeThatFits:CGSizeMake(150.0f, 16.0f)].width + 12.0f;
  35. [self.categoryNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  36. make.width.equalTo(@(categoryNameWidht));
  37. }];
  38. self.roomRoleLabel.text = [XYVocieRoomCommonMethod getVoiceRoomRoleTextWithRole:model.roomRole];
  39. CGFloat roomRoleWidht = [self.roomRoleLabel sizeThatFits:CGSizeMake(150.0f, 16.0f)].width + 12.0f;
  40. [self.roomRoleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  41. make.width.equalTo(@(roomRoleWidht));
  42. }];
  43. self.roomNameLabel.text = model.roomName;
  44. self.roomHeatLabel.text = [NSString stringWithFormat:@"%ld", model.roomHeat];
  45. }
  46. #pragma mark — Action
  47. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  48. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  49. [self _setup];
  50. [self _setupSubViews];
  51. [self _makeSubViewsConstraint];
  52. }
  53. return self;
  54. }
  55. #pragma mark - 配置属性
  56. - (void)_setup {
  57. }
  58. #pragma mark - 设置子控件
  59. - (void)_setupSubViews {
  60. [self.contentView addSubview:self.headImageView];
  61. [self.contentView addSubview:self.categoryNameLabel];
  62. [self.contentView addSubview:self.roomRoleLabel];
  63. [self.contentView addSubview:self.roomNameLabel];
  64. [self.contentView addSubview:self.roomHeatLabel];
  65. [self.contentView addSubview:self.line];
  66. }
  67. #pragma mark - 布局子控件
  68. - (void)_makeSubViewsConstraint {
  69. [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.equalTo(self.contentView).offset(21.0f);
  71. make.centerY.equalTo(self.contentView);
  72. make.width.height.equalTo(@38.0f);
  73. }];
  74. [self.categoryNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
  76. make.top.equalTo(self.headImageView).offset(1.0f);
  77. make.height.equalTo(@16.0f);
  78. make.width.equalTo(@40.0f);
  79. }];
  80. [self.roomRoleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
  82. make.top.equalTo(self.categoryNameLabel.mas_bottom).offset(5.0f);
  83. make.height.equalTo(@16.0f);
  84. make.width.equalTo(@40.0f);
  85. }];
  86. [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.equalTo(self.categoryNameLabel.mas_right).offset(10.0f);
  88. make.centerY.equalTo(self.categoryNameLabel);
  89. make.right.lessThanOrEqualTo(self.roomHeatLabel.mas_left).offset(-10.0f);
  90. }];
  91. [self.roomHeatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.right.equalTo(self.contentView).offset(-20.0f);
  93. make.centerY.equalTo(self.contentView);
  94. }];
  95. [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
  97. make.bottom.right.equalTo(self.contentView);
  98. make.height.equalTo(@(LINE_HEIGHT));
  99. }];
  100. [self.headImageView addViewBorder:Color_Clear redian:38/2];
  101. [self.categoryNameLabel addViewBorder:Color_Clear redian:8];
  102. [self.roomRoleLabel addViewBorder:Color_Clear redian:4];
  103. }
  104. #pragma mark - Getter/Setter
  105. - (UIImageView *)headImageView {
  106. if (!_headImageView) {
  107. _headImageView = [UIImageView new];
  108. _headImageView.clipsToBounds = YES;
  109. _headImageView.contentMode = UIViewContentModeScaleAspectFill;
  110. }
  111. return _headImageView;
  112. }
  113. - (UILabel *)categoryNameLabel {
  114. if (!_categoryNameLabel) {
  115. _categoryNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
  116. _categoryNameLabel.textAlignment = NSTextAlignmentCenter;
  117. _categoryNameLabel.backgroundColor = ColorFromHexString(@"#65CAA6");
  118. }
  119. return _categoryNameLabel;
  120. }
  121. - (UILabel *)roomRoleLabel {
  122. if (!_roomRoleLabel) {
  123. _roomRoleLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
  124. _roomRoleLabel.textAlignment = NSTextAlignmentCenter;
  125. _roomRoleLabel.backgroundColor = ColorFromHexString(@"#7184F7");
  126. }
  127. return _roomRoleLabel;
  128. }
  129. - (UILabel *)roomNameLabel {
  130. if (!_roomNameLabel) {
  131. _roomNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
  132. }
  133. return _roomNameLabel;
  134. }
  135. - (UILabel *)roomHeatLabel {
  136. if (!_roomHeatLabel) {
  137. _roomHeatLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font(16)];
  138. _roomHeatLabel.textAlignment = NSTextAlignmentRight;
  139. }
  140. return _roomHeatLabel;
  141. }
  142. - (UIView *)line {
  143. if (!_line) {
  144. _line = [UIView new];
  145. _line.backgroundColor = Color_line;
  146. }
  147. return _line;
  148. }
  149. @end