MOLiveMsgSystemTipCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // MOLiveMsgSystemTipCell.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/2/17.
  6. //
  7. #import "MOLiveMsgSystemTipCell.h"
  8. @implementation MOLiveMsgSystemTipCell
  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.right.equalTo(self.contentView).offset(-MOBgViewOffSet);
  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.bgView addSubview:self.contentTextView];
  29. [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.equalTo(self.bgView).offset(0.0);
  31. make.right.equalTo(self.bgView).offset(0.0);
  32. make.centerY.equalTo(self.bgView);
  33. make.height.equalTo(@16.0);
  34. }];
  35. }
  36. - (void)awakeFromNib {
  37. [super awakeFromNib];
  38. // Initialization code
  39. }
  40. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  41. [super setSelected:selected animated:animated];
  42. // Configure the view for the selected state
  43. }
  44. - (void)setCellModel:(MORtmEntity *)cellModel{
  45. _cellModel = cellModel;
  46. MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)cellModel.data;
  47. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:jsonEntity.content];
  48. [attributedString addAttribute:NSForegroundColorAttributeName value:kBaseTextHightlightColor_1 range:NSMakeRange(0, [attributedString length])];
  49. // 设置字体大小的属性
  50. [attributedString addAttribute:NSFontAttributeName value:MOTextLabelFont range:NSMakeRange(0, attributedString.length)];
  51. self.contentTextView.attributedText = attributedString;
  52. CGFloat contentHeight = cellModel.cellHeight;
  53. if(contentHeight < MORtmContentMixHeight){
  54. contentHeight = MORtmContentMixHeight;
  55. }
  56. [self.contentTextView mas_updateConstraints:^(MASConstraintMaker *make) {
  57. make.height.equalTo(@(contentHeight));
  58. }];
  59. }
  60. #pragma mark - Lazy
  61. - (UIView *)bgView
  62. {
  63. if (_bgView == nil)
  64. {
  65. _bgView = [UIView new];
  66. _bgView.backgroundColor = MONormalBgViewColor;
  67. }
  68. return _bgView;
  69. }
  70. - (MOMsgContentTextView *)contentTextView{
  71. if(!_contentTextView){
  72. _contentTextView = [MOMsgContentTextView new];
  73. _contentTextView.backgroundColor = [UIColor clearColor];
  74. _contentTextView.textContainerInset = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);//UITextView原本文字距离左右有间距,设置负数消除边距
  75. _contentTextView.editable = NO;
  76. _contentTextView.scrollEnabled = NO;//防止滑出屏幕又滑入时有时单行文字消失
  77. _contentTextView.userInteractionEnabled = NO;
  78. _contentTextView.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
  79. }
  80. return _contentTextView;
  81. }
  82. @end