Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Auto Layout in iOS Auto Layout in Code Equally Spaced Views

Marcos Reboucas
Marcos Reboucas
12,890 Points

Wouldn't be better to use a stackview?

Well I don't know if it's exactly the same thing but I've created this example in 2 minutes in Interface Builder without any line of code using a stackview with 4 UIViews inside, aligning the stackview to the centerX, pining it's top and bottom to the same distance from the top and bottom container margins and giving the 4 UIViews inside the same height and width.

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

You could do it in Interface builder. They are doing it in code, though, as an alternative. That's probably why this course is called "Auto Layout in Code" ;). That is a matter of preference, I have fought endless fights with other devs. Either approach has its pros and cons, I will not go into detail here. It's never a bad idea to know the programmatic and IB approach, though. Also keep in mind that UIStackView is only available in iOS 9 and later. Many apps still support iOS 7, some of them even iOS 6 (yes, I am looking at you, WhatsApp).