尝试修复房间聊天列表显示问题

This commit is contained in:
edwinQQQ
2024-11-28 18:45:28 +08:00
parent a6af37e51b
commit b7ebe93013
16 changed files with 678 additions and 241 deletions

View File

@@ -26,10 +26,9 @@
}
- (void)setContent:(NSAttributedString *)content {
_content = content;
self.rowHeight = [self heightForAttributedText:content
maxWidth:kRoomMessageMaxWidth];
_content = content;
// CGFloat width = isMSRTL() ? 10 : 0;
////// width = self.vipIcon.length > 0 ? width + 15 : width;
@@ -56,6 +55,17 @@
}
- (CGFloat)heightForAttributedText:(NSAttributedString *)attributedText maxWidth:(CGFloat)maxWidth {
CGSize containerSize = CGSizeMake(maxWidth, CGFLOAT_MAX);
YYTextContainer *_container = [YYTextContainer containerWithSize:containerSize];
_container.maximumNumberOfRows = 0; //
YYTextLayout *_layout = [YYTextLayout layoutWithContainer:_container text:attributedText];
CGFloat textHeight = _layout.textBoundingSize.height;
return textHeight + self.contentTopMargin + self.contentBottomMargin + self.cellBottomMargin;
// return [attributedText.string boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kRoomMessageDefalutFont]} context:nil].size.height;
// YYTextContainer
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake(maxWidth, CGFLOAT_MAX); //
@@ -63,29 +73,45 @@
//
// @
NSInteger index = 0;
NSMutableAttributedString *mutableAttributedText = [attributedText mutableCopy];
[mutableAttributedText enumerateAttribute:YYTextAttachmentAttributeName
inRange:NSMakeRange(0, mutableAttributedText.length)
options:0
usingBlock:^(id value, NSRange range, BOOL *stop) {
if ([value isKindOfClass:[YYTextAttachment class]]) {
// TODO:
YYTextAttachment *attachment = (YYTextAttachment *)value;
NSLog(@" ---00--- : %@", attachment.content);
if (attachment.content == nil) {
attachment.content = [[UIView alloc] init]; //
NSValue *v = [self.extraSizeArray xpSafeObjectAtIndex:index];
if (value) {
UIView *placeholderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [v CGSizeValue].width, [v CGSizeValue].height)];
attachment.content = placeholderView; // 使
} else {
*stop = YES;
NSMutableAttributedString *mutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:attributedText.copy];
if (isMSRTL()) {
NSInteger index = 0;
[mutableAttributedText enumerateAttribute:YYTextAttachmentAttributeName
inRange:NSMakeRange(0, mutableAttributedText.length)
options:0
usingBlock:^(id value, NSRange range, BOOL *stop) {
if ([value isKindOfClass:[YYTextAttachment class]]) {
// TODO:
YYTextAttachment *attachment = (YYTextAttachment *)value;
// NSLog(@" ---00--- : %@", attachment.content);
if (attachment.content && [attachment.content isKindOfClass:[NetImageView class]]) {
NSValue *v = [self.extraSizeArray xpSafeObjectAtIndex:index];
NSString *tempString = @"";
if (value) {
CGSize size = [v CGSizeValue];
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
// attachment.content = view;
if (size.width <= 20) {
tempString = @"ABCD";
} else if (size.width <=40) {
tempString = @"ABCDEF";
} else {
tempString = @"ABCDEFGH";
}
}
NSAttributedString *replaceString = [[NSAttributedString alloc] initWithString:tempString
attributes:@{
NSFontAttributeName: kFontRegular(kRoomMessageDefalutFont),
NSForegroundColorAttributeName: [UIColor whiteColor]
}];
[mutableAttributedText replaceCharactersInRange:range withAttributedString:replaceString];
}
}
}
}];
}];
}
// YYTextLayout
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:mutableAttributedText];