MORedRainTipCell.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // MORedRainTipCell.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/10/29.
  6. //
  7. #import "MORedRainTipCell.h"
  8. @implementation MORedRainTipCell
  9. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  10. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  11. if (self != nil) {
  12. self.contentView.transform = CGAffineTransformMakeScale(1, -1);
  13. self.backgroundColor = [UIColor clearColor];
  14. self.selectionStyle = UITableViewCellSelectionStyleNone;
  15. [self setupUI];
  16. }
  17. return self;
  18. }
  19. - (void)setupUI{
  20. [self.contentView addSubview:self.bgView];
  21. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.left.equalTo(self.contentView).offset(MOBgViewOffSet);
  23. make.width.equalTo(@(MOBgViewMaxWidth));
  24. make.top.equalTo(self.contentView).offset(MOBgViewOffSet);
  25. make.bottom.equalTo(self.contentView).offset(-MOBgViewOffSet);
  26. }];
  27. self.bgView.layer.cornerRadius = 10.0;
  28. [self.contentView addSubview:self.redTagImgView];
  29. [self.redTagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.centerY.equalTo(self.bgView);
  31. make.height.equalTo(@48.0);
  32. make.width.equalTo(@44.0);
  33. make.left.equalTo(self.bgView).offset(2.0);
  34. }];
  35. [self.bgView addSubview:self.bubbleImgView];
  36. [self.bubbleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.equalTo(self.bgView).offset(-0.0);
  38. make.right.equalTo(self.bgView).offset(0.0);
  39. make.top.equalTo(self.bgView).offset(-0.0);
  40. make.bottom.equalTo(self.bgView).offset(0.0);
  41. }];
  42. self.bubbleImgView.layer.cornerRadius = 14.0;
  43. self.bubbleImgView.layer.masksToBounds = YES;
  44. [self.bgView addSubview:self.contentTextView];
  45. [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.equalTo(self.redTagImgView.mas_right).offset(2.0);
  47. make.right.equalTo(self.bgView).offset(-2.0);
  48. make.top.equalTo(self.bgView).offset(5.0);
  49. make.bottom.equalTo(self.bgView);
  50. }];
  51. }
  52. - (void)awakeFromNib {
  53. [super awakeFromNib];
  54. // Initialization code
  55. }
  56. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  57. [super setSelected:selected animated:animated];
  58. // Configure the view for the selected state
  59. }
  60. - (void)setCellModel:(MORtmEntity *)cellModel{
  61. _cellModel = cellModel;
  62. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)cellModel.data;
  63. NSString *userName = jsonEntity.activitySuperLucky2.user.username;
  64. NSString *luckyTipStr = [NSString stringWithFormat:@"Super Lucky %@",[MOTextAESTools smallTip]];
  65. NSString *redRainTipStr = @"Red Envelope Rain";
  66. NSString *endText = [NSString stringWithFormat:@"%@ Win %@ %@ is coming...",userName,luckyTipStr,redRainTipStr];
  67. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:endText attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]}];
  68. [self base_yellow_colorfulStringWith:endText AndNameStr:userName And:attributedString];
  69. [self base_blue_colorfulStringWith:endText AndNameStr:luckyTipStr And:attributedString];
  70. [self base_yellow_colorfulStringWith:endText AndNameStr:redRainTipStr And:attributedString];
  71. // 设置字体大小的属性
  72. [attributedString addAttribute:NSFontAttributeName value:[MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr] range:NSMakeRange(0, endText.length)];
  73. self.contentTextView.attributedText = attributedString;
  74. }
  75. + (CGFloat)getTheCellHeightWith:(MORtmEntity *)entity{
  76. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)entity.data;
  77. NSString *userName = jsonEntity.activitySuperLucky2.user.username;
  78. NSString *luckyTipStr = [NSString stringWithFormat:@"Super Lucky %@",[MOTextAESTools smallTip]];
  79. NSString *redRainTipStr = @"Red Envelope Rain";
  80. NSString *endText = [NSString stringWithFormat:@"%@ Win %@ %@ is coming...",userName,luckyTipStr,redRainTipStr];
  81. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:endText attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]}];
  82. [attributedString addAttribute:NSFontAttributeName value:[MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr] range:NSMakeRange(0, endText.length)];
  83. CGSize size = [attributedString boundingRectWithSize:CGSizeMake((MOBgViewMaxWidth - 44.0 - 2.0 * 2 - 2.0), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
  84. return (size.height + 12.0);
  85. }
  86. - (NSMutableAttributedString *)base_yellow_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr And:(NSMutableAttributedString *)attributedString {
  87. // 创建属性字符串,整体颜色为白色
  88. if(nameStr.length != 0){
  89. NSRange redRange = [contentStr rangeOfString:nameStr];
  90. if(redRange.location != NSNotFound){
  91. // 将最后三个字符的颜色设置为红色
  92. [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#FFF391" alpha:1.0] range:redRange];
  93. }
  94. }
  95. return attributedString;
  96. }
  97. - (NSMutableAttributedString *)base_blue_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr And:(NSMutableAttributedString *)attributedString {
  98. // 创建属性字符串,整体颜色为白色
  99. if(nameStr.length != 0){
  100. NSRange redRange = [contentStr rangeOfString:nameStr];
  101. if(redRange.location != NSNotFound){
  102. // 将最后三个字符的颜色设置为红色
  103. [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#67EBFF" alpha:1.0] range:redRange];
  104. }
  105. }
  106. return attributedString;
  107. }
  108. #pragma mark - Lazy
  109. - (UIView *)bgView
  110. {
  111. if (_bgView == nil)
  112. {
  113. _bgView = [UIView new];
  114. _bgView.backgroundColor = [UIColor clearColor];
  115. }
  116. return _bgView;
  117. }
  118. - (UIImageView *)redTagImgView{
  119. if(!_redTagImgView){
  120. _redTagImgView = [[UIImageView alloc] init];
  121. _redTagImgView.contentMode = UIViewContentModeScaleAspectFit;
  122. [_redTagImgView setImage:[UIImage imageNamed:@"icon_red_rain"]];
  123. }
  124. return _redTagImgView;
  125. }
  126. - (UIImageView *)bubbleImgView{
  127. if(!_bubbleImgView){
  128. _bubbleImgView = [[UIImageView alloc] init];
  129. _bubbleImgView.contentMode = UIViewContentModeScaleToFill;
  130. NSArray *colorArr = @[[MOTools colorWithHexString:@"#BA2C15" alpha:0.8],[MOTools colorWithHexString:@"#FF9F16" alpha:0.8]];
  131. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 120.0, 50.0) Colors:colorArr GradientType:0];
  132. [_bubbleImgView setImage:image];
  133. }
  134. return _bubbleImgView;
  135. }
  136. - (MOMsgContentTextView *)contentTextView{
  137. if(!_contentTextView){
  138. _contentTextView = [MOMsgContentTextView new];
  139. _contentTextView.backgroundColor = [UIColor clearColor];
  140. _contentTextView.textContainerInset = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);//UITextView原本文字距离左右有间距,设置负数消除边距
  141. _contentTextView.editable = NO;
  142. _contentTextView.scrollEnabled = NO;//防止滑出屏幕又滑入时有时单行文字消失
  143. _contentTextView.userInteractionEnabled = NO;
  144. _contentTextView.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  145. }
  146. return _contentTextView;
  147. }
  148. @end