Create a layout with 2 UIViews
in a UIStackView
like so:
Create an outlet for your UIStackView
to your UIViewController
. Call addArrangedSubview
on your UIStackView
in viewDidLoad
to change the order. See snippet below.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var stackView: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
// Switches order of the stackView
stackView.addArrangedSubview(self.stackView.subviews[0])
}
}
This should be the result:
The addArrangedSubview
takes the given view and adds it to the end of the arrangedSubviews array. In our case we take the red view at index[0] and add it on the end (right) of the UIStackView
.