Write Programmatic Constraints for Swift Projects
Great layouts!
4 min readNov 15, 2020
Photo by John Towner @heytowner
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.1, and Swift 5.3
Prerequisites:
- You will be expected to be aware how to make a Single View Application in Swift
- This article assumes that you are coding 100% programatically, and are using loadView for which I use this technique
- This article uses a UINavigationController
- A guard is mentioned in this article
- Closures are mentioned in passing
Terminology
Constraints: A constraint on the layout of a view
Storyboard: A way to graphically layout the UI in Xcode
Removing the Storyboard
Although this isn’t really part of this tutorial (there is a full guide on this here but essentially you can select Main.storyboard
in the project inspector: