Programmatically Navigating a UIPageViewController using a UISegmentedControl

Let’s learn how to navigate a UIPageViewController using a UISegmentedControl in iOS. The UIPageViewController provides a way to display pages of content, where each page is managed by its own view controller. The UISegmentedControl displays segments and allows users to switch between them. We’ll begin by setting up the UISegmentedControl and UIPageViewController, then move on to connecting them by programmatically navigating the UIPageViewController based on the selection in the UISegmentedControl....

Autolayout DSL

Programmatic layout is great, but Apple’s Auto Layout is a bit heavy. Apples take on this: Whenever possible, use Interface Builder to set your constraints. Not the best advice considering the previously discussed benefits of programmatic layouts. Many frameworks exist to alleviate the problem. SnapKit, PureLayout and Anchorage are all viable options. In most cases introducing relevant dependencies is fine and has many benefits but the negatives are: requiring dependency management (SPM, CocoaPods, Carthage) adding additional imports unneeded code bloat, such as importing Alamofire for one simple network request I build many little projects....

Programmatic Auto Layout UIScrollViews

Programmatic layout rules. Some benefits: Single source of truth for your UI. Less context switching from code to interface builder. Less noise from storyboards, xibs, segues etc. No XML merge conflicts. Easier to review and debug. More flexibility for if-else scenarios, animations etc. There’s probably more. UIScrollView is great too. Simple layouts nested in a scroll view are common when you don’t need a table view or collection view and the additional complexity they bring....