Mobile App Development for iOS
Notes Topics Weekly Resources Graded work Professor Code examplesUntil January 2010, the task of user interface layout was an easy task (ha ha). The only issue was portrait vs. landscape orientation on the iPhone. Since 2008, when the iOS SDK was released, Xcode and Interface Builder provided a way to use layout “constraints” (and scrolling views) to handle these situations.
Then, the iPad was introduced, and its larger screen. Up next, in September 2012, with the release of iPhone 5 and its larger screen, changed this task for iPhone apps. Since then, chaos. (Ha ha.)
The current approach is Auto Layout. Before continuing, read/skim these sections of the Auto Layout Guide:
Working with Constraints in Interface Builder
Since iOS development began in 2008, developers were (and still are) required to use points, and NOT PIXELS, when considering screen size measurements.
As developers, we need to know a few things about screen sizes. First, the screen origin is the upper-left corner - that’s 0 x and 0 y.
While other sources (here, here) are more complete, the essential need-to-know is that the screen size for a few iPhone models in portrait orientation are shown below:
Model | Diagonal size (marketing/product info) |
Points size | Pixel resolution | PPI density |
---|---|---|---|---|
7 or 8 | 4.7 inch | 320 points horizontal x 568 points vertical |
Don’t care | Don’t care |
7 Plus or 8 Plus |
5.5 inch | 414 x 736 | ” | ” |
X or XS | 5.8 inch | 375 x 812 | ” | ” |
XR | 6.1 inch | 414 x 896 | ” | ” |
XS Max | 6.5 inch | 414 x 896 | ” | ” |
The bottom line is that we’re typically working with a reasonably narrow range of values, but we still must adapt our user interfaces.
The following sections cover two specific layout tasks. To be an effective iOS developer, you must learn these and additional techniques for your apps. A warning, it’s not easy, but the task does get easier with practice and learning.
On typical (e.g. iPhone 8 and larger) screens, there is a default left and right margin of 20 points.
On smaller screens, the margin is 16 points. This fact alone will help reveal the benefits of using these layout techniques, because the margin used will match the device.
When working with the storyboard, on the Edit > Canvas menu, you can choose to show a number of visual helpers. Check a few of them out, as they will help as you learn and practice these layout techniques.
The following will be demonstrated by the professor, in class. The idea is that you will be able to do the same on your own.
Scenario:
How to:
Then:
The following will be demonstrated by the professor, in class. The idea is that you will be able to do the same on your own.
Scenario:
How to:
These exercises are the bare minimum to get started.
As noted above, layout done right isn’t easy, but the task does get easier with practice and learning.