iOS故事板中表行高的大小类

我用Swift和storyboard开发了一个iOS应用程序。 我放置了一个表,我需要根据屏幕类更改表格单元格高度,但我在表格选项中找不到这样的选项。 我看到单元格高度由“表视图/行高”选项定义,但它不支持类大小。

出现此问题的原因是我使用大小类在单元格原型中设置标签字体,因此对于较大的屏幕,字体较大,但行大小不能按大小类更改。 显然,我需要更高的行来获得更大的字体。 我应该用什么方法来实现它?

Obj-C代码也会这样做。

让我回答一下我自己的问题 – 在iOS 8中,可以使用UITableViewAutomaticDimension为表格的行高启用单元格的自动布局:

 override func viewDidLoad() { super.viewDidLoad() tableView.estimatedRowHeight = 89 tableView.rowHeight = UITableViewAutomaticDimension } 

estimatedRowHeight需要设置。

链接:

http://natashatherobot.com/ios-8-self-sizing-table-view-cells-with-dynamic-type/

http://www.appcoda.com/self-sizing-cells/

https://stackoverflow.com/a/28918600/1028256

使用UITableView Delegate通过代码进行设置。

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { //check the conditions and return the row height. return 71.0; } 

您也可以在Swift中找到类似的委托。