动态计算表中单元格cell的高度:
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
var size = new CGSize(tableView.Bounds.Width, float.MaxValue);
var detailDict = new NSDictionary(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(13));
var detailRect = ((NSString)“ 所要计算的字符串”.WeakGetBoundingRect(size, NSStringDrawingOptions.UsesLineFragmentOrigin, detailDict, null);
var detailHeight = detailRect.Size.Height;
var textDict = new NSDictionary(UIStringAttributeKey.Font, UIFont.SystemFontOfSize(15));
var textRect = ((NSString)“ 所要计算的字符串”.WeakGetBoundingRect(size, NSStringDrawingOptions.UsesLineFragmentOrigin, textDict, null);
var textHeight = textRect.Size.Height;
return detailHeight + textHeight + 30;
}
本文介绍了一种动态计算UITableView中单元格高度的方法。通过使用NSString的WeakGetBoundingRect方法结合UIStringAttributeKey.Font属性设置字体大小,可以精确计算出不同字符串内容在特定宽度下的实际显示高度。
943

被折叠的 条评论
为什么被折叠?



