WeView 2

An alternative to iOS Auto Layout

Tutorial 14: Example

Here’s an example whose layout is responsive to changes of orientation and device:

Getting Started

We’ll use one WeView (the rootView) to layout the contents of the screen.

The Activity Indicator

We’ll start with the easiest element of the layout, the activity indicator.

The Header

The Pillbox Buttons

The Background

The background image is the trickiest part of the layout.

If we simply wanted to stretch the background image’s UIImageView to fill the screen, we could simply:

Layout Snapshot

But simply stretching the image to fill the screen distorts its content. We want to preserve the aspect ratio of the image as we stretch it, although this will cause the image to extend offscreen and be cropped.

Layout Snapshot

Therefore, we wrap the the background image in a separate WeView and add the UIImageView using [addSubviewWithFillLayoutWAspectRatio].

The Final Code