【发布时间】:2017-09-29 07:47:55
【问题描述】:
我有一个表格视图,其高度是屏幕的 70%自动调整到 tablerows 内容然后它会很棒但我找不到任何相关的东西。
那该怎么做呢?
【问题讨论】:
-
这是用于行自动高度的。我怀疑整个表格及其自动高度
标签: ios uitableview autolayout nslayoutconstraint
我有一个表格视图,其高度是屏幕的 70%自动调整到 tablerows 内容然后它会很棒但我找不到任何相关的东西。
那该怎么做呢?
【问题讨论】:
标签: ios uitableview autolayout nslayoutconstraint
你可以像下面那样做
IBOutlet 的高度限制为UITableView
你会根据你的数据/行找到tableView的高度
tableView.contentSize.height
现在您需要根据以下条件更改高度限制
if tableView.contentSize.height < UIScreen.main.bounds.size.height { // Instead of UIScreen.main.bounds.size.height, change as per your requirment
yourTblHeightConstraints.constant = tableView.contentSize.height
self.view.layoutIfNeeded()
}
else {
yourTblHeightConstraints.constant = UIScreen.main.bounds.size.height // Instead of UIScreen.main.bounds.size.height, change here as you need
self.view.layoutIfNeeded()
}
【讨论】: