Information Technology Reference
In-Depth Information
Chapter 7:Getting Started
with Interface Builder
In This Chapter
Understanding nib files
Getting started with IB
Creating a simple iOS project with IB
Comparing IB in Xcode 4 with Xcode 3
Although Interface Builder (IB) can be used as a UI editor, you must understand that it's a more general object
management tool.
Understanding IB
In Xcode, IB has five functions:
You can use IB to design your application's UI. The UI design includes one or more windows and views,
with associated controls—objects such as buttons, sliders, text boxes, and so on. The design process presets
the properties of these objects. For example, you can set the default position of an OS X window and control
whether it has a drop shadow. Similarly, when you add a button to a UI, you use IB to set its position in the
window or view, set its color, and so on. Optionally, you can define custom graphics and other more special-
ized features.
You can use IB to pre-instantiate objects in your application. Any object you add to a nib file is created in
memory when the file is loaded. This option is completely general: Objects do not have to be visible on
screen or be part of a UI. The standard application templates for both iOS and OS X rely on this feature to
load the core application classes.
You can use IB to create your own kit of UI objects. Very advanced developers can create a complete ex-
ternal library of custom UI objects, with associated code. This is a major project and outside the scope of this
topic. But simple customization is relatively easy. For example, the layout of a standard table cell can be de-
signed in IB as a stand-alone object, and then loaded and repeated as needed in one or more tables. In this
mode, you use IB to create useful nib files with collections of objects that can be loaded as needed. These ob-
jects can be fragments of a UI, or they can be data collections.
You can use IB to link code features to UI objects. User actions and events are sent to your code using ac-
tions— methods that are triggered in the code when the user interacts with a view or a control. UI object
properties such as size, position, color, state, text, and so on are set with outlets . Outlets link Objective-C
properties to corresponding properties in UI objects. Objects that have custom features are subclassed,
which tells IB that a UI object has been modified with extra code that you define.
In OS X only, IB objects can include bindings. Bindings link objects and properties indirectly, with semi-
automated format translation. In outline, when your code sets a bound property, the UI is updated automatic-
Search WWH ::




Custom Search