With the Xcode 7 and iOS 9 release, we received many “gifts” to help us be more productive in terms of development and maybe a bit happier developers. There is still, as always, room for improvement, but each step that moves us forward, and any Xcode feature which makes our work a bit easier, is more than appreciated.
Now for me the most exciting feature is Stack View. How does it work? UIStackView is a non-rendering subclass of UIView, intended for managing layout of its subviews. It works along a vertical or horizontal axis, with the exact arrangement determined by the distribution, alignment and spacing properties like equal distribution of views, equal spaces between views, centered vies, etc. It’s a virtual container where you can put different views, and you don’t have to worry about setting up any constraints. You just drag and drop the views into the Stack View, and when the code is running, the layout will behave exactly as it was pre-defined. You can also select multiple existing views and group them in a new Stack View with just one click.
You can nest together as many Stack Views as you want, so in theory you can create almost any layout using this technique. If you are familiar with the spacers technique and constraint multipliers (which you should be :) ), you’ll love how much time you'll save using Stack Views. It’s like getting a free cake instead of having to buy all the ingredients to bake your own cake. Yes, maybe your cake will taste a bit better, but the time demand is incomparable!
Using all the tricks that Auto Layout offers, you’ll save time, and many developers are already in love with it. But there are still a lot of developers out there, who don't care about responsive layouts. Some of them complain Auto Layout is too complicated, and others say it’s a nuisance having to deal with so many different constraints and priorities. So what is the easiest way to force all developers to make attractive responsive layouts with minimum effort? The answer is Stack Views.
Should we only use Stack Views from now on? Should we just toss out all our knowledge on constraints and techniques? Of course not. We will still work with constraints, but much less than before. Most of the time, you will need a mixture of constraints and Stack Views. When you need to add some cool features like animations, it’s best to use proven tools.
I’m looking forward to seeing better and more responsive layouts. After playing around with tvOS, I can see that the new Apple TV is the main reason why Apple introduced this new way of making layouts. As always, the software must be ready before the new hardware released. Stay tuned!