Chapter 7. More adaptive layout
This chapter covers
- Adapting layouts for size classes
- Adapting layouts with stack views
In this chapter, we’ll look at a useful feature for manipulating layouts in different environments, called size classes. We’ll use size classes to adjust layouts programmatically and from within Interface Builder.
We’ll then explore stack views—a feature introduced in iOS 9 that speeds up the process of setting up an adaptive layout (in most cases).
Auto layout is great for adjusting a layout based on constraints, but sometimes a layout requires more-significant adjustments based on the device type, screen size, or orientation.
For example, you may want
- A bigger font size in the huge iPad Pro screen than on the tiny iPhone 4S.
- A view laid out differently on iPhones when in landscape or portrait mode.
- To provide additional buttons in the iPad version of your app.
- To lay out content differently when your app is in slide-over or split-view mode.
How can you make these sorts of adjustments to a layout?
In older versions of Xcode, you may have had multiple storyboards for iPads and iPhones. Or perhaps you used the device orientation or window size to determine the environment for laying out a scene. Along with increasing numbers of devices, split view controllers (introduced in iOS 8), and slide-over and split-view multitasking modes (introduced in iOS 9), adjusting a layout to its environment became more complex.