XYHotGiveRewardUserListTableViewCell.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // XYHotGiveRewardUserListTableViewCell.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/11/16.
  6. //
  7. #import "XYHotGiveRewardUserListTableViewCell.h"
  8. #import "XYHotGiveRewardUserListModel.h"
  9. @interface XYHotGiveRewardUserListTableViewCell ()
  10. @property (nonatomic, strong) UIImageView *headImageView;
  11. @property (nonatomic, strong) UILabel *userNameLabel;
  12. @property (nonatomic, strong) UILabel *giftTitleLabel;
  13. @property (nonatomic, strong) UILabel *giftNameLabel;
  14. @property (nonatomic, strong) UIImageView *giftImageView;
  15. @end
  16. @implementation XYHotGiveRewardUserListTableViewCell
  17. + (instancetype)cellWithTableView:(UITableView *)tableView {
  18. XYHotGiveRewardUserListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:XYHotGiveRewardUserListTableViewCell.className];
  19. if (cell == nil) {
  20. cell = [[XYHotGiveRewardUserListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:XYHotGiveRewardUserListTableViewCell.className];
  21. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  22. }
  23. return cell;
  24. }
  25. - (void)configureModel:(XYHotGiveRewardUserListModel *)model {
  26. [self.headImageView sd_setImageWithURL:UrlForString(model.userAvatar) placeholderImage:placeholderUserIcon()];
  27. self.userNameLabel.text = model.userName;
  28. self.giftTitleLabel.text = @"打赏";
  29. self.giftNameLabel.text = model.giftName;
  30. [self.giftImageView sd_setImageWithURL:UrlForString(model.giftIcon) placeholderImage:placeholderImage()];
  31. }
  32. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  33. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  34. [self setupUI];
  35. }
  36. return self;
  37. }
  38. - (void)setupUI {
  39. [self.contentView addSubview:self.headImageView];
  40. [self.contentView addSubview:self.userNameLabel];
  41. [self.contentView addSubview:self.giftImageView];
  42. [self.contentView addSubview:self.giftNameLabel];
  43. [self.contentView addSubview:self.giftTitleLabel];
  44. [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.equalTo(self.contentView).offset(16.0f);
  46. make.width.height.equalTo(@32.0f);
  47. make.centerY.equalTo(self.contentView);
  48. }];
  49. [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.equalTo(self.headImageView.mas_right).offset(8.0f);
  51. make.centerY.equalTo(self.contentView);
  52. make.height.equalTo(@20.0f);
  53. }];
  54. [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.right.equalTo(self.contentView).offset(-16.0f);
  56. make.centerY.equalTo(self.contentView);
  57. make.width.height.equalTo(@32.0f);
  58. }];
  59. [self.giftNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.right.equalTo(self.giftImageView.mas_left).offset(-4.0f);
  61. make.centerY.equalTo(self.contentView);
  62. make.height.equalTo(@17.0f);
  63. }];
  64. [self.giftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.right.equalTo(self.giftNameLabel.mas_left).offset(-4.0f);
  66. make.centerY.equalTo(self.contentView);
  67. make.height.equalTo(@17.0f);
  68. make.left.greaterThanOrEqualTo(self.userNameLabel.mas_right).offset(10.0f);
  69. }];
  70. [self.headImageView addViewBorder:Color_Clear redian:32/2];
  71. }
  72. #pragma mark - lazy
  73. - (UIImageView *)headImageView {
  74. if (_headImageView == nil) {
  75. _headImageView = [UIImageView new];
  76. _headImageView.clipsToBounds = YES;
  77. _headImageView.contentMode = UIViewContentModeScaleAspectFill;
  78. }
  79. return _headImageView;
  80. }
  81. - (UILabel *)userNameLabel {
  82. if (_userNameLabel == nil) {
  83. _userNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
  84. }
  85. return _userNameLabel;
  86. }
  87. - (UILabel *)giftTitleLabel {
  88. if (_giftTitleLabel == nil) {
  89. _giftTitleLabel = [UILabel createLabelTextColor:Color_TextGray fount:Font(12)];
  90. _giftTitleLabel.textAlignment = NSTextAlignmentRight;
  91. _giftTitleLabel.text = @"打赏";
  92. }
  93. return _giftTitleLabel;
  94. }
  95. - (UILabel *)giftNameLabel {
  96. if (_giftNameLabel == nil) {
  97. _giftNameLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font(12)];
  98. _giftNameLabel.textAlignment = NSTextAlignmentRight;
  99. }
  100. return _giftNameLabel;
  101. }
  102. - (UIImageView *)giftImageView {
  103. if (_giftImageView == nil) {
  104. _giftImageView = [UIImageView new];
  105. _giftImageView.clipsToBounds = YES;
  106. _giftImageView.contentMode = UIViewContentModeScaleAspectFill;
  107. }
  108. return _giftImageView;
  109. }
  110. - (void)awakeFromNib {
  111. [super awakeFromNib];
  112. // Initialization code
  113. }
  114. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  115. [super setSelected:selected animated:animated];
  116. // Configure the view for the selected state
  117. }
  118. @end