删除UIStackView中的自定义间距

问题描述 投票:2回答:1

我有一个带有三个子视图的堆栈视图:

stackView.spacing = 8.0

stackView.addArrangeSubview(view1)
stackView.addArrangeSubview(view2)
stackView.addArrangeSubview(view3)

有时,我在view2之后添加自定义间距:

stackView.setCustomSpacing(24.0, after: view2)

现在,我要删除自定义间距。是否可以使用UIStackView?我能想到的唯一方法是

stackView.setCustomSpacing(8.0, after: view2)

但是如果我将stackView的间距更改为8.0以外的其他值,这会中断,因为view2之后的间距将保持8.0。

ios swift user-interface uistackview
1个回答
0
投票
您可以将hack用作固定高度的空视图。

let view1 = UIView(height: 50) // init with height is a custom convenience init let view2 = UIView(height: 35) let spacing = UIView(height: 20) let stackView = UIStackView(arrangedSubviews: [view1, spacing, view2]) view.addSubview(stackView) // constraint if needed

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.