Chapter 11. Building simple iOS views

 

This chapter covers

  • iOS storyboard resources
  • Laying out controls using auto layout and constraints
  • Supporting multiple screen sizes using size classes
  • Adding images to support multiple screen sizes using asset catalogs
  • Creating view controllers
  • The view controller lifecycle

In the last two chapters we built the UIs for SquareRt and Countr on Android. In this chapter and the next, we’ll build these view layers on iOS (figure 11.1). We’ll start here by looking at how to build an iOS UI and then build the UI for SquareRt. In the next chapter we’ll look at Countr, and you’ll see some slightly more advanced UI techniques, including using table views to show lists of data, menus, and navigation.

Figure 11.1. The view layer in an MVVM app is written in platform-specific code.

The iOS SDK is different from that of Android, but the basic principles for UIs are the same—a UI layout is defined in an XML file, and there’s a class that loads this layout and provides access to the layout’s UI components. Where on Android we used Activity for the views, on iOS we use UIViewController (iOS, like macOS, has MVC built in). Android uses layout XML files, and iOS uses storyboards.

11.1. Building iOS UIs

Let’s start by thinking about our SquareRt app, which has a single view. Figure 11.2 shows the UI that we want to build.

Figure 11.2. The UI for the SquareRt app

11.2. Creating the SquareRt storyboard

11.3. Building the SquareRt view

Summary

sitemap