iOS 故事板中 table 行高的大小 class
size class for table row height in iOS storyboard
我用 Swift 和故事板开发了一个 iOS 应用程序。我放置了一个 table,我需要根据屏幕 class 更改 table 单元格高度,但我在 table 选项中找不到这样的选项。我看到单元格高度由 Table 视图/行高选项定义,但它不支持 class 大小。
出现此问题是因为我在单元格原型中使用大小 classes 设置标签字体,因此对于更大的屏幕字体更大,但行高不能根据大小更改 class .显然,我需要更高的行来显示更大的字体。我应该使用什么方法来实现它?
Obj-C 代码也可以。
使用 UITableView Delegate 通过代码设置它。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//check the conditions and return the row height.
return 71.0;
}
您也可以在 Swift 中找到类似的代表。
让我回答我自己的问题 - 在 iOS 8 中,可以为 table 的行高使用 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/
我用 Swift 和故事板开发了一个 iOS 应用程序。我放置了一个 table,我需要根据屏幕 class 更改 table 单元格高度,但我在 table 选项中找不到这样的选项。我看到单元格高度由 Table 视图/行高选项定义,但它不支持 class 大小。
出现此问题是因为我在单元格原型中使用大小 classes 设置标签字体,因此对于更大的屏幕字体更大,但行高不能根据大小更改 class .显然,我需要更高的行来显示更大的字体。我应该使用什么方法来实现它?
Obj-C 代码也可以。
使用 UITableView Delegate 通过代码设置它。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//check the conditions and return the row height.
return 71.0;
}
您也可以在 Swift 中找到类似的代表。
让我回答我自己的问题 - 在 iOS 8 中,可以为 table 的行高使用 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/