处理好评论了
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user