UIStackView Tutorial for iOS: Introducing Stack Views | raywenderlich.com

Learn how to simplify your iOS layouts with UIStackView. Layout a series of views horizontally or vertically, using alignment, distribution and spacing.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2198310-uistackview-tutorial-for-ios-introducing-stack-views

Hi Ehab,
What a great tutorial! Many thanks!
Would be interesting if you could expand on how the views are organized as it seems to be super efficient in terms of code and number of controllers and files needed.
I tried the rating (Submit Rating) but it does not seem to work - I would expect my updated rating to appear back on the stacked view with the corresponding starts but that remains unchanged. I can read Updated Rating (5), for example, but the number of starts is not changed.


Hello Bernardo,
I’m delighted to know you like the tutorial :]
The stars on the info screen are just a label, in the current implementation they don’t include the rating you submitted, it shows (supposedly) the average rating that everyone else submitted.
In a real project you want to have the average of all submissions, and recalculated with every submission.

1 Like

Great tutorial, very clearly explained. One thing I would add with the animation section is that there is a weird visual glitch when showing the weather info, some of the text overlaps the title as it’s animating in. I’m running iOS 13.3 so might be a new bug with that OS. But you can fix it with the following code in the UIView.animate closure:

UIView.animate(withDuration: 0.3) {
    self.weatherHideOrShowButton.setTitle(newButtonTitle, for: .normal)
    self.weatherInfoLabel.isHidden = shouldHideWeatherInfo
    self.weatherInfoStackView.layoutIfNeeded() // add this line

You’ll need to add an @IBOutlet for the StackView that is the immediate parent of the “weatherInfoLabel”, and hook it up via the StoryBoard:

@IBOutlet var weatherInfoStackView: UIStackView!

@sironfoot Thank you for sharing your solution - much appreciated! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!