Last updated 35 days ago by Reda Lemedenswift
When I was a student in Japan, I worked part-time at a restaurant — アルバイト arubaito as the locals call it — where I was tasked with putting away dishes during downtime. Every plate had to be stacked neatly, ready to serve as the canvas for the next gastronomic creation. Lucky for me, the universal laws of physics came in quite handy — all I had to do was pile things up, rather indiscriminately, and move on to the next task.
In contrast, iOS developers often have to jump through several conceptual hoops when laying out user interfaces. After all, placing things in an upside-down 2D coordinate system is not intuitive for anyone but geometry geeks; for the rest of us, it’s not that cut and dried.
But wait — what if we could take physical world concepts like gravity and elasticity and appropriate them for UI layouts?
As it turns out, there has been no shortage of attempts to do so since the early years of GUIs and personal computing — Motif’s XmPanedWindow and Swing’s BoxLayout are notable early specimens. These widgets are often referred to as stack-based layouts, and three decades later, they are alive and well on all major platforms, including Android’s LinearLayout and CSS flexbox, as well as Apple’s own NSStackView, UIStackView, and — new in SwiftUI — HStack, VStack, and ZStack.
This week on NSHipster, we invite you to enjoy a multi-course course detailing the most delicious morsels of this most versatile of layout APIs: UIStackView.