// // MOLiveMsgNormalTipCell.m // MiMoLive // // Created by SuperC on 2024/2/17. // #import "MOLiveMsgNormalTipCell.h" #import "MOLiveMsgBaseCell.h" @implementation MOLiveMsgNormalTipCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self != nil) { self.contentView.transform = CGAffineTransformMakeScale(1, -1); self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self setupUI]; } return self; } - (void)setupUI{ [self.contentView addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(MOBgViewOffSet); make.right.equalTo(self.contentView).offset(-MOBgViewOffSet); make.top.equalTo(self.contentView).offset(MOBgViewOffSet); make.bottom.equalTo(self.contentView).offset(-MOBgViewOffSet); }]; self.bgView.layer.cornerRadius = 12.0; self.bgView.layer.masksToBounds = YES; [self.bgView addSubview:self.bgImgView]; [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.bgView); }]; [self.bgView addSubview:self.iconImgView]; [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.equalTo(@16.0); make.centerY.equalTo(self.bgView); make.left.equalTo(self.bgView).offset(MOContentBaseLeftSpacing); }]; [self.bgView addSubview:self.rightImgView]; [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@6.0); make.height.equalTo(@9.0); make.centerY.equalTo(self.bgView); make.right.equalTo(self.bgView).offset(-MOContentBaseLeftSpacing); }]; [self.bgView addSubview:self.contentLab]; [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.bgView); make.left.equalTo(self.iconImgView.mas_right).offset(5.0); make.right.equalTo(self.rightImgView.mas_left).offset(5.0); make.height.equalTo(@20.0); }]; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)setCellModel:(MORtmEntity *)cellModel{ _cellModel = cellModel; MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)cellModel.data; self.contentLab.text = jsonEntity.content; CGFloat cellWidth = (SCREENWIDTH - MOLiveMsgLeftSpacing - MOLiveMsgRightSpacing - MOBgViewOffSet * 2); CGFloat contentLabWidth = [MOTools getWidthWithString:jsonEntity.content font:MOTextLabelFont]; CGFloat rightSpacing = cellWidth - contentLabWidth - MOContentBaseLeftSpacing - 16.0 - 5.0 - MOContentBaseLeftSpacing - 6.0; if(cellModel.type == SystemTipVip){ [self.iconImgView setImage:[UIImage imageNamed:@"icon_live_msg_vip"]]; // NSArray *colorArr = @[[MOTools colorWithHexString:@"#D6CD82" alpha:1.0],[MOTools colorWithHexString:@"#FCA08A" alpha:1.0]]; // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, cellWidth, MOTextLabelMinHeight) Colors:colorArr GradientType:0]; // [self.bgImgView setImage:image]; } else if (cellModel.type == SystemTipChat){ [self.iconImgView setImage:[UIImage imageNamed:@"icon_live_msg_chat"]]; // NSArray *colorArr = @[[MOTools colorWithHexString:@"#F418F4" alpha:1.0],[MOTools colorWithHexString:@"#912FFE" alpha:1.0]]; // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, cellWidth, MOTextLabelMinHeight) Colors:colorArr GradientType:0]; // [self.bgImgView setImage:image]; } else{ [self.iconImgView setImage:[UIImage imageNamed:@"icon_live_msg_gift"]]; // NSArray *colorArr = @[[MOTools colorWithHexString:@"#F418F4" alpha:1.0],[MOTools colorWithHexString:@"#912FFE" alpha:1.0]]; // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, cellWidth, MOTextLabelMinHeight) Colors:colorArr GradientType:0]; // [self.bgImgView setImage:image]; } [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView).offset(-rightSpacing); }]; } #pragma mark - Lazy - (UIView *)bgView { if (_bgView == nil) { _bgView = [UIView new]; _bgView.backgroundColor = MONormalBgViewColor; } return _bgView; } - (UIImageView *)bgImgView{ if(!_bgImgView){ _bgImgView = [[UIImageView alloc] init]; _bgImgView.contentMode = UIViewContentModeScaleToFill; _bgImgView.hidden = YES; } return _bgImgView; } - (UIImageView *)iconImgView{ if(!_iconImgView){ _iconImgView = [[UIImageView alloc] init]; _iconImgView.contentMode = UIViewContentModeScaleAspectFit; } return _iconImgView; } - (UILabel *)contentLab{ if (!_contentLab) { _contentLab = [[UILabel alloc] init]; _contentLab.text = @""; _contentLab.font = MOTextLabelFont; _contentLab.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]; _contentLab.textAlignment = NSTextAlignmentLeft; _contentLab.numberOfLines = 1; } return _contentLab; } - (UIImageView *)rightImgView{ if(!_rightImgView){ _rightImgView = [[UIImageView alloc] init]; [_rightImgView setImage:[UIImage imageNamed:@"icon_live_right_white"]]; _rightImgView.contentMode = UIViewContentModeScaleAspectFit; } return _rightImgView; } @end