When you move from Xcode 5 to version 6 for iOS development, one of the concepts that can be difficult to wrap your head around is Size Classes. Size Classes are great, they allow you to use a single storyboard for multiple form factors and screen orientations, but they can become very complicated as you add more and more class-specific settings and constraints.

[av_image src=’http://www.mattknott.com/wp-content/uploads/2015/03/Screen-Shot-2015-03-02-at-18.43.10-495×400.png’ attachment=’2097′ attachment_size=’portfolio’ align=’right’ animation=’pop-up’ link=’lightbox’ target=” styling=” caption=’yes’ font_size=” appearance=”]
A basic project started in the wCompact hAny size class
[/av_image]

One pitfall that’s easy for developers to make is to start laying out their app using a specific size class, for example an iPhone app may be started using wCompact hAny because the design area in the storyboard takes on a familiar landscape shape, which is less disorienting that the default wAny hAny layout you are presented with for all apps.

The challenge with this approach comes when you’ve set all of your constraints and have your layout working perfectly on a 4-inch iPhone, but when you rotate it or try it on a larger device, it all goes wrong and elements become unaligned, too large or small, and sometimes disappear altogether. The reason for this is that the constraints you set under wCompact hAny will often only be valid when those conditions are met. thankfully there is a straight forward way to get your constraints to be applied in different size classes.

Select a constraint from the Document Outline and then open up the Attributes Inspector. As you will see in the image below, you will have a tick against wC hAny, meaning this constraint is only valid in that layout, but the blank item above it (which should really be labelled wAny hAny) is not ticked. Click this to make the constraint apply across any layout.

Screen Shot 2015-03-01 at 10.02.27