feat:修正需求验收问题

This commit is contained in:
edwinQQQ
2024-11-28 10:40:21 +08:00
parent cafb009362
commit 2415016337
43 changed files with 1091 additions and 1187 deletions

View File

@@ -27,8 +27,12 @@
- (void)setContent:(NSAttributedString *)content {
_content = content;
self.rowHeight = [self heightForAttributedText:content
maxWidth:kRoomMessageMaxWidth];
// CGFloat width = isMSRTL() ? 10 : 0;
//// width = self.vipIcon.length > 0 ? width + 15 : width;
////// width = self.vipIcon.length > 0 ? width + 15 : width;
// CGSize maxSize = CGSizeMake(kRoomMessageMaxWidth - self.contentLeftMargin - self.contentRightMargin - 12, MAXFLOAT);
// YYTextContainer *container = [YYTextContainer containerWithSize:maxSize];
// container.maximumNumberOfRows = 0;
@@ -37,4 +41,59 @@
// self.rowHeight = rowHeight + width ;
}
- (CGFloat)heightForAttributedStringUsingTextKit:(NSAttributedString *)attributedString
maxWidth:(CGFloat)maxWidth {
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedString];
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX)];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[layoutManager addTextContainer:textContainer];
[textStorage addLayoutManager:layoutManager];
//
[layoutManager glyphRangeForTextContainer:textContainer];
return ceil([layoutManager usedRectForTextContainer:textContainer].size.height); //
}
- (CGFloat)heightForAttributedText:(NSAttributedString *)attributedText maxWidth:(CGFloat)maxWidth {
// YYTextContainer
YYTextContainer *container = [YYTextContainer new];
container.size = CGSizeMake(maxWidth, CGFLOAT_MAX); //
container.maximumNumberOfRows = 0; //
//
// @
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;
}
}
}
}];
// YYTextLayout
YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:mutableAttributedText];
self.textWidth = ceil(layout.textBoundingSize.width);
//
return ceil(layout.textBoundingSize.height) + self.contentTopMargin + self.contentBottomMargin + self.cellBottomMargin; //
}
@end