Updated about 21 hours ago | GitHub
On this page

Creating a Free Form View Controller

Sometimes, it’s convenient to have a long or wide view controller in Storyboard when you’re designing long or wide views. If that’s the case, configure the view controller to be freeform.

free form

Step 1: Set the view controller to be freeform

In the Storyboard, make sure the view controller is selected, then open the Size inspector (the Ruler icon), set Simulated Size to Freeform, and choose your dimensions.

Free

Step 2: Add constraints so the layout adapts at runtime

The freeform size is a design-time convenience only — at runtime the view controller’s root view is resized to the actual device screen. Storyboards use Auto Layout by default, so how your subviews respond to that resize is determined by their constraints. Sometimes you want a subview to shrink with the root view, and sometimes you want it to stay the same size.

For example, if the scene contains a scroll view, you probably want it to shrink down: pin its edges to the root view so it resizes with it. For a fixed-size UIImageView, give it width and height constraints (or rely on its intrinsic content size) so it keeps its dimensions when the root view shrinks.

A subview doesn’t need constraints, though. Since Xcode 11, each view has a Layout option in the Size inspector. Its default setting, Automatic, translates the view’s autoresizing mask into constraints whenever the view has no constraints in the storyboard, and you can also set the option to translate the autoresizing mask explicitly. For a view laid out this way, its autoresizing mask decides how it responds when the root view resizes: a flexible width or height makes the subview grow or shrink with its superview, while leaving them off keeps it a fixed size.