The simplest implementation is achieved using the Layout Anchors & UIStackViews. Visual Format Language has the advantage that it allows us to visualise the constraints, but has limitation on the kinds of constraints that can be applied. NSLayoutContraints class approach is verbose where in we have to provide information even if it is not required.
The best approach, really, is to use storyboards. Use the programmatic approach only if you want to dynamically create constraints orif you want to dynamically create UI elements.
Here is a short video I have created on this topic. I basically go over the same code and provide some explanation on how I built the project.
Download the Source Code
You can download the starter project, which is a basic project with all the other necessary code written for you. You can directly jump in and add the the constraints.
Here is the link to the completed project using Layout Anchors.
Here is the link to the completed project using Visual Formatting Language.
Here is the link to the completed project using NSLayoutConstraints.
All the projects have the implementation for the traitCollectionDidChange method.
One thought on “Creating iOS Apps without Storyboard – Part 2”
Fixed the issue with the links to the sample projects. They should be working fine now.