I would like to click and add subview at: index 3 position. But the constraint not update automatically. how can i refresh the layout when adding subview to uistack?
Thank you for your help very much
@objc func showMoreView() {
stackView.insertSubview(view3, at: 3)
stackView.superview?.layoutIfNeeded()
view.layoutIfNeeded()
}
Current Layout
view.addSubview(stackView)
stackView.addArrangedSubview(view1)
stackView.addArrangedSubview(view2)
stackView.addArrangedSubview(view4)
stackView.addArrangedSubview(view5)
2
Answers
You need to use
like that:
Documentation here
Swift provides the following
UIStackView
function to insert a view at a specified position:(see the documentation for more information)