05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

All controls come in three standard sizes: regular, small, and mini. Although you can manually<br />

change the size of a control and its contents, using one of the predefined sizes ensures that<br />

your controls will always match the rest of the system, regardless of design changes down the<br />

road. In general, Apple’s Human Interface Guidelines suggest using regular controls whenever<br />

possible, reserving the use of the smaller controls for when space is at a premium.<br />

NOTE Did you think the <strong>Mac</strong>’s usability was an accident? Far from it, every pixel has been<br />

sweated over by design experts and explained in excruciating detail in Apple’s Human Interface<br />

Guidelines. These are required reading for any <strong>Mac</strong> developer, and also interesting for<br />

any user who’d like to get to know more about what makes using a <strong>Mac</strong> such a great experience.<br />

The guidelines, usually referred to as the HIG (rhymes with dig), are available in Xcode’s<br />

documentation and online.<br />

Figure 25-10. Changing Autosizing<br />

attributes in the Inspector<br />

Moving down to the View Size subsection, you can<br />

set size and location based on any corner or edge, or the<br />

view’s center. You can also align and center multiple<br />

views. What you really want is to change the autosizing<br />

behavior, as shown in Figure 25-10.<br />

On the left side of the Autosizing section is a<br />

schematic representation of your view inside its superview.<br />

The inner rectangle represents your view. The<br />

vertical and horizontal arrows inside your view represent<br />

which direction you want your view to resize in.<br />

The struts connecting your view to the superview represent<br />

which sides of your view you want to be fixed in<br />

relation to the superview. The expected results of the settings<br />

are animated on the right.<br />

By clicking the resize directions and struts in the<br />

schematic, you can change the effects shown in the animation.<br />

A little experimentation shows that removing<br />

all the struts will enable your text area to remain centered. Save and run the interface to verify<br />

that this is so.<br />

Bindings<br />

CHAPTER 25 MAC <strong>OS</strong> X DEVELOPMENT: THE TOOLS 461<br />

As you’ve seen, even simple controls like the text field have a lot of attributes. Some of these<br />

attributes are displayed to the user, such as the title. Other attributes affect the control itself, such<br />

as its size, or whether it’s hidden. While you can set an initial state during the design of your<br />

interface, some attributes may need to change at runtime.<br />

Traditionally, getting and setting a control’s value was accomplished via an intermediary<br />

object, called a controller. A programmer would write glue code in the controller to perform the<br />

actual getting and setting of values.<br />

Cocoa’s bindings feature eliminates the need for this glue code by letting controls bind their<br />

values to other objects. For example, check boxes on a preference panel might be bound to the<br />

user defaults system. The value of a date field might be bound to the value of a date picker. Or, a<br />

user-editable value might be bound to a key in the document controller. Unlike traditional glue<br />

code, a bound value is always kept in sync automatically.<br />

The Inspector’s Bindings tab contains a list of bindable attributes. Within each binding, you<br />

can set the object, the key name, and several options. You can also set a value transformer to<br />

automatically convert between value types. For example, an object might have a URL attribute<br />

that you want to bind to another object’s path attribute. Since URLs have their own class, NSURL,<br />

and paths are instances of the NSString class, you wouldn’t be able to bind a URL to a path without<br />

the assistance of a value transformer.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!