【发布时间】:2018-06-12 17:58:44
【问题描述】:
我有多个组件作为行的 UITableViewCell,由 UIView 内的 UILabel、UIView 和 UIStackView 的混合元素组成。
单元格内的每个组件都有高度限制。我希望单元格的高度是动态的,方法是在运行时将高度约束的常数设置为零或 21,取决于它是否有要显示的内容。
// more codes like below
if let mealPref = passenger.mealPref {
mealPrefHeight.constant = 21
let title = R.string.localizable.meal_request.localized()
mealPrefLabel.text = "• \(title): \(mealPref)"
} else {
mealPrefHeight.constant = 0
}
// more codes like above
它不起作用。
我有类似的problem back then,但我认为情况不同。我读过this、this 和this。
【问题讨论】:
-
如果您在运行时更改约束的
constant,AutomaticDimension将不起作用。如果设置常量 = 21,则自动尺寸将被覆盖。
标签: ios iphone swift uitableview uiview