4
Views and the View Hierarchy

In this chapter, you will learn about views and the view hierarchy. In particular, you are going to write an app named Hypnosister that draws a full-screen set of concentric circles.

Figure 4.1  Hypnosister

Hypnosister

In Xcode, select FileNewProject... (or use the keyboard shortcut Command-Shift-N). From the iOS section, select Application, choose the Empty Application template, and click Next.

Enter Hypnosister for the product name and BNR for the class prefix, as shown in Figure 4.2. Make sure iPhone is selected from the Devices drop down and make sure the Use Core Data box is unchecked.

Figure 4.2  Configuring Hypnosister

Configuring Hypnosister

Hypnosister will not have any user interaction so that you can focus on how views are drawn to the screen. Let’s start with a little theory of views and the view hierarchy.

View Basics

  • A view is an instance of UIView or one of its subclasses.

  • A view knows how to draw itself.

  • A view handles events, like touches.

  • A view exists within a hierarchy of views. The root of this hierarchy is the application’s window.

In Chapter 1, you created four views for the Quiz app: two instances of UIButton and two instances of UILabel. You created and configured these views in Interface Builder, but you can also create views programmatically. In Hypnosister, you will create views programmatically.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset