Online Book Reader

Home Category

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

By Root 979 0
the fonts at all. Consistent font usage is an important part of the GUI consistency that the Mac is known for. Most labels, buttons, and other controls use the Lucida Grande font by default. You can change the size of some labels, and switch them between Bold and Regular to highlight different things, but leave the font itself as it is.

Figure 2-16. Mac OS X’s font window is available for use in all Cocoa applications. It’s also used in Interface Builder to let you change the font, size, and font attributes of text you place on your interface.

Once you have your label looking just the way you like, we’ll make one more set of changes in Interface Builder. Then, we’ll go back to Xcode, put some finishing touches on our application, then run it. If you’re running short on screen space, you can close the font window, the color picker, and even your application’s main window (the one that says “Hello World”). Just make sure you don’t close the nib’s main window yet (the one with the icons in it), because we’re not quite done with this nib.

Using the Menu Editor


If the menu editor (Figure 2-4, lower left) is not showing, open it by double-clicking the MainMenu icon in your nib’s main window. The menu editor allows you to edit the contents of your application’s menu bar. By default, MainMenu.xib comes with many of the standard menu items that you would want in a Cocoa application. We’ll get into the specifics of working with the menu bar later in the book, but here’s a quick overview. As you build your application, you’ll provide actions for the each menu item you want to support. When the menu bar is drawn, if an action to respond to an item is available, the item is enabled. If no action is available, the item is disabled (grayed out). Some actions are provided for you, such as those provided for text-related menus like Copy or Paste. For items you will never use, the best approach is just to delete them.

For the moment, don’t worry about the mechanics of working with the menu bar.

Let’s customize the menu bar for our “Hello World” application. If you’re running Snow Leopard, the menu has been pre-configured to use your application’s name in the relevant places, but for projects created on Leopard, you’ll see the text

“NewApplication” in five different places in the menu bar and individual menus. All of these need to be changed to reflect the actual application name. If you’re using Snow Leopard or later, you can skip ahead to the next section (“Creating Your Application Icon”).

First, change the name in the application menu. The application menu is the menu immediately to the right of the Apple menu, and is named after the running application. The application menu lets the user know which application is frontmost. Because your application does not control the Apple menu, the Apple menu does not appear in the nib’s menu editor. The left-most menu that you can edit here is the application menu. The menu title is NewApplication. Double-click the menu title. It will become editable. Change the application menu title from NewApplication to Hello World (Figure 2-17). Click on another menu or item, or type return to commit the change.

Figure 2-17. Using the menu editor to change the application menu title from NewApplication to “Hello World”

Remember, the application’s name appears in five places. That’s one down, and four to go. Next, single-click the freshly changed Hello World menu, which should cause the actual menu to drop down so you can edit its contents (Figure 2-18).

Figure 2-18. Expanding the application menu in Interface Builder’s menu editor

Inside the application menu, there are three more occurrences of NewApplication that need to be changed to Hello World. The process here is exactly the same as it was for changing the menu name. Just double-click on a menu item to put it into edit mode, type the new value, then hit return, or click out to commit the change. Make the change to the About, Hide, and Quit items. Four down, one to go.

Next, click on the Help menu, the right-most

Return Main Page Previous Page Next Page

®Online Book Reader