MOLiveMsgFanClubTipCell.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // MOLiveMsgFanClubTipCell.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/6/23.
  6. //
  7. #import "MOLiveMsgFanClubTipCell.h"
  8. @interface MOLiveMsgFanClubTipCell ()
  9. @property (nonatomic, strong) UILabel *tipLab;
  10. @property (nonatomic, strong) UIImageView *tagImgView;
  11. /** 气泡的点击手势(可以根据需要将这个手势从视图中移除或禁止) */
  12. @property (nonatomic, strong, readonly) UITapGestureRecognizer *bubbleTapGestureRecognizer;
  13. @end
  14. @implementation MOLiveMsgFanClubTipCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if (self != nil) {
  18. self.contentView.transform = CGAffineTransformMakeScale(1, -1);
  19. self.backgroundColor = [UIColor clearColor];
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. [self setupUI];
  22. }
  23. return self;
  24. }
  25. - (void)setupUI{
  26. [self.contentView addSubview:self.bgView];
  27. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.equalTo(self.contentView).offset(MOBgViewOffSet);
  29. make.width.equalTo(@(MOBgViewMaxWidth));
  30. make.top.equalTo(self.contentView).offset(MOBgViewOffSet);
  31. make.bottom.equalTo(self.contentView).offset(-MOBgViewOffSet);
  32. }];
  33. self.bgView.layer.cornerRadius = 10.0;
  34. [self.bgView addSubview:self.contentTextView];
  35. [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.equalTo(self.bgView).offset(MOContentLeftAndRighSpacing);
  37. make.right.equalTo(self.bgView).offset(-MOContentLeftAndRighSpacing);
  38. make.height.equalTo(@16.0);
  39. }];
  40. [self.bgView addSubview:self.tagImgView];
  41. [self.tagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.right.equalTo(self.bgView).offset(-14);
  43. make.width.height.equalTo(@12.0);
  44. make.bottom.equalTo(self.bgView).offset(-7);
  45. }];
  46. [self.bgView addSubview:self.tipLab];
  47. [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.equalTo(self.bgView).offset(MOContentLeftAndRighSpacing);
  49. make.centerY.equalTo(self.tagImgView);
  50. make.right.equalTo(self.tagImgView.mas_left).offset(-2);
  51. make.height.equalTo(@18.0);
  52. }];
  53. self.bgView.userInteractionEnabled = YES;
  54. _bubbleTapGestureRecognizer = [UITapGestureRecognizer new];
  55. [_bubbleTapGestureRecognizer addTarget:self action:@selector(bubbleTapped:)];
  56. _bubbleTapGestureRecognizer.delegate = self;
  57. [self.bgView addGestureRecognizer:self.bubbleTapGestureRecognizer];
  58. }
  59. - (void)bubbleTapped:(UITapGestureRecognizer *)recognizer
  60. {
  61. MOLogV(@"触发了点击");
  62. self.cellTapBlock ? self.cellTapBlock(self.cellModel) : nil;
  63. }
  64. - (void)awakeFromNib {
  65. [super awakeFromNib];
  66. // Initialization code
  67. }
  68. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  69. [super setSelected:selected animated:animated];
  70. // Configure the view for the selected state
  71. }
  72. - (void)setCellModel:(MORtmEntity *)cellModel{
  73. _cellModel = cellModel;
  74. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)cellModel.data;
  75. NSMutableAttributedString *titleAttr = [MOTextTools creteTextWith:cellModel];
  76. self.contentTextView.attributedText = titleAttr;
  77. CGFloat width = cellModel.contentWidth + MOContentLeftAndRighSpacing * 2.0 + MOContentOffSet * 3.0 ;
  78. if(width > MOBgViewMaxWidth){
  79. width = MOBgViewMaxWidth;
  80. }
  81. if(width < MOBgViewMinWidth){
  82. width = MOBgViewMinWidth;
  83. }
  84. [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
  85. make.width.equalTo(@(width));
  86. }];
  87. }
  88. #pragma mark - Lazy
  89. - (UIView *)bgView
  90. {
  91. if (_bgView == nil)
  92. {
  93. _bgView = [UIView new];
  94. _bgView.backgroundColor = MONormalBgViewColor;
  95. }
  96. return _bgView;
  97. }
  98. - (MOMsgContentTextView *)contentTextView{
  99. if(!_contentTextView){
  100. _contentTextView = [MOMsgContentTextView new];
  101. _contentTextView.backgroundColor = [UIColor clearColor];
  102. _contentTextView.textContainerInset = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);//UITextView原本文字距离左右有间距,设置负数消除边距
  103. _contentTextView.editable = NO;
  104. _contentTextView.scrollEnabled = NO;//防止滑出屏幕又滑入时有时单行文字消失
  105. _contentTextView.userInteractionEnabled = NO;
  106. _contentTextView.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  107. }
  108. return _contentTextView;
  109. }
  110. - (UILabel *)tipLab{
  111. if(!_tipLab){
  112. _tipLab = [[UILabel alloc] init];
  113. _tipLab.textColor = [MOTools colorWithHexString:@"#FFE254" alpha:1.0];
  114. _tipLab.font = [MOTextTools mediumFont:13.0];
  115. _tipLab.textAlignment = NSTextAlignmentLeft;
  116. _tipLab.text = NSLocalString(@"mimo_2_live_rtm_fan_club_tip_3");
  117. }
  118. return _tipLab;
  119. }
  120. - (UIImageView *)tagImgView{
  121. if(!_tagImgView){
  122. _tagImgView = [[UIImageView alloc] init];
  123. _tagImgView.image = [UIImage imageNamed:@"v_2_new_yellow_right"];
  124. _tagImgView.contentMode = UIViewContentModeScaleAspectFit;
  125. }
  126. return _tagImgView;
  127. }
  128. @end