How is it possible to add a arranged subview in a particular index in a UIStackView?
something like:
stackView.addArrangedSubview(nibView, atIndex: inde
if you don't want to struggle with the index you can use this extension
extension UIStackView {
func insertArrangedSubview(_ view: UIView, belowArrangedSubview subview: UIView) {
arrangedSubviews.enumerated().forEach {
if $0.1 == subview {
insertArrangedSubview(view, at: $0.0 + 1)
}
}
}
func insertArrangedSubview(_ view: UIView, aboveArrangedSubview subview: UIView) {
arrangedSubviews.enumerated().forEach {
if $0.1 == subview {
insertArrangedSubview(view, at: $0.0)
}
}
}
}
You mean you want to insert, not add:
func insertArrangedSubview(_ view: UIView, atIndex stackIndex: Int)