[英]How to get/calculate margin width of grouped UITableView on iPad or iPhone
I have a grouped table view that I use to display several properties of a model. 我有一个分组的表格视图,用于显示模型的多个属性。 Those properties can be longish so I calculate the height of the cells in
tableView:heightForCellAtIndexPath:
using NSString's
sizeWithFont:constrainedToSize:lineBreakMode:
method. 这些属性可能很长,所以我使用
NSString's
sizeWithFont:constrainedToSize:lineBreakMode:
方法来计算tableView:heightForCellAtIndexPath:
单元格的高度。 I'm now making the app universal so I need to pass correct cell width to this method. 我现在正在使该应用程序通用,因此我需要将正确的单元格宽度传递给此方法。 And I can't simply use
tableView's
width as it's "margins" are much wider on iPad. 而且我不能简单地使用
tableView's
宽度,因为它的“边距”在iPad上要宽得多。
The second issue with those margins I have, is that I have a custom UIView
for section in that tableView
and I wan't to align it's contents with cells contents. 我所拥有的这些空白的第二个问题是,我在
tableView
有一个自定义UIView
for section,并且我不想将其内容与单元格内容对齐。
So the question is: how do I get or calculate the width of margins in a grouped UITableView
? 所以问题是:如何获取或计算分组的
UITableView
的边距宽度?
I think you can SET width instead of calculating something like that 我认为您可以设置宽度而不是像这样计算
CGSize constraintSize;
constraintSize.height = CGFLOAT_MAX;
if (isItIpad)
constraintSize.width = 500.0f;
else if (group=1)
constraintSize.width = 250.0f;
end if
and use it in your sizeWithFont:constrainedToSize:lineBreakMode: 并在您的sizeWithFont:constrainedToSize:lineBreakMode中使用它:
or you can calculate max (or min) width in the group (sizeWithFont:) and use it 或者您可以计算组中的最大(或最小)宽度(sizeWithFont :)并使用它
我在应用程序中使用了以下内容(它还支持方向更改):
CGSize constraintSize = CGSizeMake(self.view.frame.size.width - 40.0f, MAXFLOAT);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.