// // TXGroupNoticeMessageCell.m // TUIChat // // Created by 王智 on 2024/8/30. // #import "TXGroupNoticeMessageCell.h" #import "TXGroupNoticeMessageContentView.h" #import "Masonry.h" @interface TXGroupNoticeMessageCell () @property (nonatomic, strong) TXGroupNoticeMessageContentView *noticeContentView; @end @implementation TXGroupNoticeMessageCell - (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.noticeContentView]; [self.noticeContentView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.avatarView.mas_right).offset(10); make.top.mas_equalTo(self.avatarView.mas_top); make.width.mas_equalTo(245); make.bottom.mas_equalTo(self.container.mas_bottom).offset(-10); }]; } - (void)fillWithData:(TXGroupNoticeMessage *)data { [super fillWithData:data]; [self.noticeContentView configCellWithMsgTitle:data.msgTitle content:data.msgContent]; CGFloat height = [self getContentViewHeight:data]; if (data.direction == MsgDirectionIncoming) { [self.noticeContentView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.avatarView.mas_right).offset(10); make.top.mas_equalTo(self.avatarView.mas_top); make.width.mas_equalTo(245); make.height.mas_equalTo(height); }]; } else { [self.noticeContentView mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.avatarView.mas_left).offset(-10); make.top.mas_equalTo(self.avatarView.mas_top); make.width.mas_equalTo(245); make.height.mas_equalTo(height); }]; } } - (CGFloat)getContentViewHeight:(TUIMessageCellData *)data { TXGroupNoticeMessage *noticeMsg = (TXGroupNoticeMessage *)data; if (![TXGroupNoticeMessageCell isEmptyString:noticeMsg.msgContent]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.maximumLineHeight = 21; paragraphStyle.minimumLineHeight = 21; UIFont *font = [UIFont systemFontOfSize:16.0f]; CGFloat height = [noticeMsg.msgContent boundingRectWithSize:CGSizeMake(221, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font} context:nil].size.height + 1; CGFloat contentHeight = height + 64 + 11; return contentHeight; } else { return 64 + 11; } } - (TXGroupNoticeMessageContentView *)noticeContentView { if (!_noticeContentView) { _noticeContentView = [TXGroupNoticeMessageContentView shareIntance]; } return _noticeContentView; } - (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 { TXGroupNoticeMessage *noticeMsg = (TXGroupNoticeMessage *)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:noticeMsg.msgContent]) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.maximumLineHeight = 21; paragraphStyle.minimumLineHeight = 21; UIFont *font = [UIFont systemFontOfSize:16.0f]; CGFloat height = [noticeMsg.msgContent boundingRectWithSize:CGSizeMake(221, CGFLOAT_MAX) options:(NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height + 6; CGFloat contentHeight = height + 64 + 11; return CGSizeMake(width, contentHeight); } else { return CGSizeMake(width, 64 + 11); } } + (BOOL)isEmptyString:(NSString *)str { if (str == nil || str.length == 0) { return YES; } return NO; } @end