| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // MORedRainTipCell.m
- // MiMoLive
- //
- // Created by SuperC on 2024/10/29.
- //
- #import "MORedRainTipCell.h"
- @implementation MORedRainTipCell
- - (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.width.equalTo(@(MOBgViewMaxWidth));
- make.top.equalTo(self.contentView).offset(MOBgViewOffSet);
- make.bottom.equalTo(self.contentView).offset(-MOBgViewOffSet);
- }];
- self.bgView.layer.cornerRadius = 10.0;
-
- [self.contentView addSubview:self.redTagImgView];
- [self.redTagImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.bgView);
- make.height.equalTo(@48.0);
- make.width.equalTo(@44.0);
- make.left.equalTo(self.bgView).offset(2.0);
- }];
-
- [self.bgView addSubview:self.bubbleImgView];
- [self.bubbleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bgView).offset(-0.0);
- make.right.equalTo(self.bgView).offset(0.0);
- make.top.equalTo(self.bgView).offset(-0.0);
- make.bottom.equalTo(self.bgView).offset(0.0);
-
- }];
- self.bubbleImgView.layer.cornerRadius = 14.0;
- self.bubbleImgView.layer.masksToBounds = YES;
-
- [self.bgView addSubview:self.contentTextView];
- [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.redTagImgView.mas_right).offset(2.0);
- make.right.equalTo(self.bgView).offset(-2.0);
- make.top.equalTo(self.bgView).offset(5.0);
- make.bottom.equalTo(self.bgView);
- }];
- }
- - (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;
- NSString *userName = jsonEntity.activitySuperLucky2.user.username;
-
- NSString *luckyTipStr = [NSString stringWithFormat:@"Super Lucky %@",[MOTextAESTools smallTip]];
- NSString *redRainTipStr = @"Red Envelope Rain";
-
- NSString *endText = [NSString stringWithFormat:@"%@ Win %@ %@ is coming...",userName,luckyTipStr,redRainTipStr];
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:endText attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]}];
- [self base_yellow_colorfulStringWith:endText AndNameStr:userName And:attributedString];
- [self base_blue_colorfulStringWith:endText AndNameStr:luckyTipStr And:attributedString];
- [self base_yellow_colorfulStringWith:endText AndNameStr:redRainTipStr And:attributedString];
-
- // 设置字体大小的属性
- [attributedString addAttribute:NSFontAttributeName value:[MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr] range:NSMakeRange(0, endText.length)];
-
- self.contentTextView.attributedText = attributedString;
-
- }
- + (CGFloat)getTheCellHeightWith:(MORtmEntity *)entity{
- MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)entity.data;
- NSString *userName = jsonEntity.activitySuperLucky2.user.username;
-
- NSString *luckyTipStr = [NSString stringWithFormat:@"Super Lucky %@",[MOTextAESTools smallTip]];
- NSString *redRainTipStr = @"Red Envelope Rain";
-
- NSString *endText = [NSString stringWithFormat:@"%@ Win %@ %@ is coming...",userName,luckyTipStr,redRainTipStr];
-
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:endText attributes:@{NSForegroundColorAttributeName:[MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]}];
- [attributedString addAttribute:NSFontAttributeName value:[MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr] range:NSMakeRange(0, endText.length)];
-
- CGSize size = [attributedString boundingRectWithSize:CGSizeMake((MOBgViewMaxWidth - 44.0 - 2.0 * 2 - 2.0), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
- return (size.height + 12.0);
- }
- - (NSMutableAttributedString *)base_yellow_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr And:(NSMutableAttributedString *)attributedString {
-
- // 创建属性字符串,整体颜色为白色
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#FFF391" alpha:1.0] range:redRange];
- }
- }
-
- return attributedString;
- }
- - (NSMutableAttributedString *)base_blue_colorfulStringWith:(NSString *)contentStr AndNameStr:(NSString *)nameStr And:(NSMutableAttributedString *)attributedString {
-
- // 创建属性字符串,整体颜色为白色
- if(nameStr.length != 0){
- NSRange redRange = [contentStr rangeOfString:nameStr];
- if(redRange.location != NSNotFound){
- // 将最后三个字符的颜色设置为红色
- [attributedString addAttribute:NSForegroundColorAttributeName value:[MOTools colorWithHexString:@"#67EBFF" alpha:1.0] range:redRange];
- }
- }
-
- return attributedString;
- }
- #pragma mark - Lazy
- - (UIView *)bgView
- {
- if (_bgView == nil)
- {
- _bgView = [UIView new];
- _bgView.backgroundColor = [UIColor clearColor];
- }
- return _bgView;
- }
- - (UIImageView *)redTagImgView{
- if(!_redTagImgView){
- _redTagImgView = [[UIImageView alloc] init];
- _redTagImgView.contentMode = UIViewContentModeScaleAspectFit;
- [_redTagImgView setImage:[UIImage imageNamed:@"icon_red_rain"]];
- }
- return _redTagImgView;
- }
- - (UIImageView *)bubbleImgView{
- if(!_bubbleImgView){
- _bubbleImgView = [[UIImageView alloc] init];
- _bubbleImgView.contentMode = UIViewContentModeScaleToFill;
-
- NSArray *colorArr = @[[MOTools colorWithHexString:@"#BA2C15" alpha:0.8],[MOTools colorWithHexString:@"#FF9F16" alpha:0.8]];
- UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 120.0, 50.0) Colors:colorArr GradientType:0];
- [_bubbleImgView setImage:image];
- }
- return _bubbleImgView;
- }
- - (MOMsgContentTextView *)contentTextView{
- if(!_contentTextView){
- _contentTextView = [MOMsgContentTextView new];
- _contentTextView.backgroundColor = [UIColor clearColor];
- _contentTextView.textContainerInset = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);//UITextView原本文字距离左右有间距,设置负数消除边距
- _contentTextView.editable = NO;
- _contentTextView.scrollEnabled = NO;//防止滑出屏幕又滑入时有时单行文字消失
- _contentTextView.userInteractionEnabled = NO;
- _contentTextView.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
- }
- return _contentTextView;
- }
- @end
|