Online Book Reader

Home Category

Learn Objective-C on the Mac - Mark Dalrymple [9]

By Root 874 0
Next, click and drag the label toward the left side of the window. As it gets near the left edge of the window, you should notice a dashed blue line to the left of your text (see Figure 2-8). Interface Builder uses these blue guidelines to indicate that the item you are dragging is aligned properly with the items around it. In this case, the guideline is telling you that your label is the proper distance from the left edge of the window.

NOTE: One of the things that have made using the Mac such a pleasant experience over the years has been the consistency of the user interface. In the vast majority of Mac applications, you can count on the ability to press ⌘W to close a window, ⌘S to save, and ⌘P to print, regardless of what program you are in. If you’re going to write software for the Mac, you should know these “rules of consistency.” Apple lays out these rules in their “Human Interface Guidelines” (also know as the HIG). Interface Builder’s little blue guidelines are there expressly to make it easier for you to conform to the Human Interface Guidelines. You can find a copy of the HIG here:

http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines

Figure 2-8. When you move the object near the edges, blue lines appear.

The Inspector Window


Another important Interface Builder window looks very similar to the library window, so much so that you might get them confused. This one’s called the inspector. To open the inspector, select Inspector from the Tools menu or type ⌘I. The inspector is typically closed when you launch Interface Builder for the first time.

The inspector is a context-sensitive window that displays information about the currently selected object. Click a window and the inspector displays information about that window (see Figure 2-9). Click your label and the inspector displays information about that label. You get the idea.

Figure 2-9. The inspector showing attributes for the window

Take a look at the inspector window shown in Figure 2-9. Notice the seven small tabs that span the top of the window. When pressed, each tab will turn the window into one of seven different inspector types.

There is also a keyboard shortcut for each of the inspectors, starting with ⌘1 to go to the left-most inspector (the attributes inspector, which you’ll use the most) through ⌘7 for the right-most inspector. Table 2-1 lists the command-key equivalents for each of the seven inspectors.

Table 2-1. Key Combination Shortcuts for Interface Builder’s Inspectors

The Attributes Inspector


Let’s start off with a look at the attributes inspector. If you don’t see it, press ⌘1 to bring up the window, then single-click on your label. The inspector should look like Figure 2-10.

You can use the attributes inspector to change the appearance of your label. You can change attributes like text alignment, border, and scrolling behavior. Interestingly, several of these fields will actually do nothing. Go ahead and type something into the Placeholder field. Doesn’t change the appearance of the label at all, does it?

What’s going on here? When you pull a Label out of the library, you are grabbing an instance of the NSTextField class. The NSTextField class is used for both static and editable text fields. In an editable text field, the placeholder is that gray text you see in some text fields when they are empty, which tells you what the field is for. Figure 2-11 shows an example of placeholder text, used to indicate that the text typed in this field will be sent to Google to initiate a search.

Figure 2-10. The attribute inspector showing all the attributes of the label that can be edited in Interface Builder

Figure 2-11. The search box in Safari uses a placeholder to tell you that typing text into that field will initiate a Google web search.

When a text field is configured as a label, there’s no need for a placeholder. It doesn’t hurt to provide one, but it doesn’t help, either.

There are too many context-specific attributes to be able to enumerate them all in

Return Main Page Previous Page Next Page

®Online Book Reader