Chapter 3. Introduction to UI Kit

UI Kit is the largest iPhone framework in terms of file size, and rightly so—it's responsible for all user interface functions, from creating windows and text boxes to reading multi-touch gestures and hardware sensors. All of the graphical pleasantries that make the iPhone seem easy to use rely on the UI Kit framework to deliver a polished and unified interface. The same UI Kit APIs are available to all iPhone applications, and understanding how to use this framework will allow you to take advantage of some of the tools and effects that make Apple's own stock apps spectacular.

UI Kit is more than a mere user interface kit; it is also the runtime foundation for iPhone GUI applications. When you launch an application, its main function instantiates a UIApplication object within UI Kit. This class is the base class for all applications having a user interface on the iPhone, and it provides the application access to the iPhone's higher-level functions. In addition to this, common application-level services such as resigning control to other applications and becoming active again are functions of the UIApplication class.

All iPhone applications created in Xcode are linked to the UI Kit framework by default, so you won't need to do anything special to connect it to your application. To create the skeleton for the UI Kit application examples used in this chapter, you'll be instructed to use Xcode to create a new window-based application, view-based application, or navigation-based application. Each uses a slightly different set of files, which we'll provide the code for.

While there are several UI Kit components that you can create using Interface Builder, many developers choose to create UI objects directly within their code. What's more, your application might end up as a hybrid between the standard objects created with Interface Builder and more proprietary view classes. This chapter covers the basic UI Kit objects (that is, the most foundational to most applications) and helps you to choose which to code directly and which to design with Interface Builder. Even if you use Interface Builder to design your entire UI, this chapter will show you how to interact with the objects you create.