【发布时间】:2021-11-16 07:37:43
【问题描述】:
我有一个包含 UIStackView 的容器组(radio 组),并且该堆栈视图包含一堆可以具有不同大小的项目,具体取决于它们的标签内容。它们有两个标签,可以跨越多行。
很遗憾,我无法正确布置项目的内容。我尝试以许多不同的方式重新排序约束,我尝试将标签内容嵌套到容器视图中,但我似乎无法让堆栈视图的内容正确布局。它总是会下溢并截断标签的最末端,或者它的大小会稍微太小并迫使内容自己挤进框架:
项目的约束是:
NSLayoutConstraint.activate([
radioView.topAnchor.constraint(equalTo: topAnchor, constant: contentInsets.top)
radioView.leftAnchor.constraint(equalTo: leftAnchor, constant: contentInsets.left),
bottomAnchor.constraint(greaterThanOrEqualTo: radioView.bottomAnchor, constant: contentInsets.bottom),
textLabel.topAnchor.constraint(equalTo: topAnchor, constant: contentInsets.top),
textLabel.leftAnchor.constraint(equalTo: radioView.rightAnchor, constant: labelsSpacingLeft),
textLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -contentInsets.right),
detailTextLabel.topAnchor.constraint(equalTo: textLabel.bottomAnchor, constant: detailTextLabelSpacingTop),
detailTextLabel.leftAnchor.constraint(equalTo: radioView.rightAnchor, constant: labelsSpacingLeft),
detailTextLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -contentInsets.right),
bottomAnchor.constraint(greaterThanOrEqualTo: detailTextLabel.bottomAnchor, constant: contentInsets.bottom),
])
【问题讨论】:
标签: ios swift autolayout nslayoutconstraint uistackview