// // TXLiveShareCell.m // TUIChat // // Created by 王智 on 2023/8/10. // #import "TXLiveShareCell.h" #import "TXShareLiveCellContentView.h" #import "Masonry.h" @interface TXLiveShareCell () @property (nonatomic, strong) TXShareLiveCellContentView *liveContentView; @end @implementation TXLiveShareCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self configUI]; } return self; } - (void)configUI { [self.container addSubview:self.liveContentView]; [self.liveContentView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.container.mas_right); make.top.mas_equalTo(self.container.mas_top); make.width.mas_equalTo(260); make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10); }]; } - (void)fillWithData:(TXLiveShareMessage *)data { [super fillWithData:data]; [self.liveContentView configCellWithShareAvatar:data.teacherAvatar teacherName:data.teacherName liveDesc:data.liveDescMessage]; if (data.direction == MsgDirectionIncoming) { [self.liveContentView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.container.mas_left); make.top.mas_equalTo(self.container.mas_top); make.width.mas_equalTo(260); make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10); }]; } else { [self.liveContentView mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.container.mas_right); make.top.mas_equalTo(self.container.mas_top); make.width.mas_equalTo(260); make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10); }]; } } - (TXShareLiveCellContentView *)liveContentView { if (!_liveContentView) { _liveContentView = [TXShareLiveCellContentView shareIntance]; } return _liveContentView; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } #pragma mark - TUIMessageCellProtocol + (CGSize)getContentSize:(TUIMessageCellData *)data { TXLiveShareMessage *shareMsg = (TXLiveShareMessage *)data; CGFloat width = ([UIScreen mainScreen].bounds.size.width > [UIScreen mainScreen].bounds.size.height ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width); if (![self isEmptyString:shareMsg.liveDescMessage]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:4];//调整行间距 CGFloat height = [shareMsg.liveDescMessage boundingRectWithSize:CGSizeMake(260, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} context:nil].size.height + 6; CGFloat contentHeight = height + 123 + 20; return CGSizeMake(width, contentHeight); } else { return CGSizeMake(width, 123 + 20); } } + (BOOL)isEmptyString:(NSString *)str { if (str == nil || str.length == 0) { return YES; } return NO; } @end