nicklockwood / layout

A declarative UI framework for iOS
MIT License
2.23k stars 97 forks source link

Trouble with UIStackView.addArrangedSubView #182

Open neptunus opened 4 years ago

neptunus commented 4 years ago

When adding arranged subviews to a Layout stack view programmatically, it doesn't update its height from the initial 0, so all the subviews get placed at (0, 0). However, when I add the subviews to the stack view XML, they stack up correctly — they're probably calculating their children's heights in that case.

So does anyone know what I'm missing? I guess I want to confirm (before I spend more time banging my head against the rock) whether or not there's an obvious method to solve this problem, or if I need to look into calculating the heights myself.

Edit: I do need to mention that setting the stack view's frame to a new CGRect doesn't have any effect. Reading out its .frame.height value confirms that it's still at 0.0 after something like stackView?.frame = CGRect(x:0, y:0, width:300, height:600). All of this is happening in my UIViewController's viewDidLoad() method.