iOS故事板中表行高的大小类 [英] size class for table row height in iOS storyboard
问题描述
我使用Swift和storyboard开发了一个iOS应用程序。我放置了一个表,我需要根据屏幕类更改表格单元格高度,但我在表格选项中找不到这样的选项。我看到单元格高度由表视图/行高度选项定义,但它不支持类大小。
I develop an iOS app with Swift and storyboard. I placed a table and I need to change table cell height depending on screen class, but I can't find such option in table options. I see that cell height is defined by Table View / Row height option, but it doesn't support class sizes.
出现此问题是因为我在使用大小类的单元格原型,因此对于更大的屏幕,字体更大,但每个大小类不能更改行高。显然,我需要更高的行来获得更大的字体。我应该用什么方法来实现呢?
This problem happens because I set fonts of labels in the cell prototype using size classes, so for bigger screens fonts are bigger, but row height can't be changed per size class. I need a higher row for bigger fonts, obviously. What approach should I use to achieve it?
Obj-C代码也会这样做。
Obj-C code will do too.
推荐答案
让我回答一下我自己的问题 - 在iOS 8中,可以使用 UITableViewAutomaticDimension
为表格的行高启用单元格的自动布局:
Let me answer my own question - in iOS 8 it's possible to enable auto layout for cells using UITableViewAutomaticDimension
for table's row height:
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/
<小时ef =https://stackoverflow.com/a/28918600/1028256> https://stackoverflow.com/a/28918600/1028256
这篇关于iOS故事板中表行高的大小类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!