处理好评论了

This commit is contained in:
2026-01-16 19:09:54 +08:00
parent 619c02f236
commit 3dfb8f31e2
9 changed files with 211 additions and 402 deletions

View File

@@ -37,4 +37,42 @@
}
}
- (CGFloat)calculateCellHeightWithMaxWidth:(CGFloat)maxWidth {
if (self.cachedCellHeight > 0) {
return self.cachedCellHeight;
}
// Cell
// (68) + (28) + (8) + + (8) + (40) + (16)
// = maxWidth - 68 - 28 - 8 - 8 - 40 - 16
CGFloat contentWidth = maxWidth - 68 - 28 - 8 - 8 - 40 - 16;
//
NSMutableString *fullText = [NSMutableString stringWithString:self.userName];
if (self.replyToUserName.length > 0) {
[fullText appendFormat:@" 回复 @%@", self.replyToUserName];
}
[fullText appendFormat:@"%@", self.content];
UIFont *contentFont = [UIFont systemFontOfSize:14];
CGRect contentRect = [fullText boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName: contentFont}
context:nil];
CGFloat contentHeight = ceil(contentRect.size.height);
//
CGFloat timeHeight = 14; // 11
// = (8) + + (4) + + (8)
CGFloat totalHeight = 8 + contentHeight + 4 + timeHeight + 8;
// +
CGFloat minHeight = 8 + 28 + 8;
totalHeight = MAX(totalHeight, minHeight);
self.cachedCellHeight = totalHeight;
return totalHeight;
}
@end