Online Book Reader

Home Category

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

By Root 935 0
same name. Let’s change the name to something that fits by single-clicking the Main Window Controller icon, waiting a second, then single-clicking the text below the icon. The icon’s name should become editable. Change it to read Main Controller, which still identifies what this instance is, but also fits in the space provided.

Setting Up the Window


Our next order of business is to design our application’s interface. In the main nib window, double-click the window’s icon to open our application’s main window. Press ⌘1 to open up the Attributes Inspector. We’re going to make some changes, so the attributes match what you see in Figure 3-7.

Figure 3-7. The attributes inspector lets you configure piles of options for many kinds of objects in your nib files. Configure your window to match the settings shown here.

Change the window’s title from Button to Press a Button. The field below Title is labeled Autosave. If we provide a value in this field, our application will automatically save the location, size, and other information about the window in our user preferences so that when the user launches the application again, he or she will find the window exactly where it was left. It doesn’t matter what value you put here, as long as it is unique. If you use the same autosave name for any two objects, one of them will fail to save. Type in mainWindow here.

Right under the Autosave field are three checkboxes that control some of the fundamental behavior of the window. The Close checkbox enables or disables the ability to close the window. In a utility application with only one window, you might want to uncheck this box so that the window can’t be closed. If this box is unchecked, both the red close button in the window’s title bar and the Close menu item will be disabled. If you allow the window to be closed, you should provide a way to make the window visible again. Alternatively, if your application is a utility that consists of only one window, it is acceptable to have the application quit when the window is closed. Later on in this chapter, we’ll configure our application to quit when this window is closed, so leave the Close checkbox as it is. In later chapters, you’ll learn how to make closed windows visible again.

The Minimize checkbox controls whether the window can be minimized to the dock using the yellow button in the window’s title bar or from selecting Minimize from the Window menu. As a general rule, windows should be able to be minimized. There are exceptions to this, such as utility windows that are only visible when your application is front-most, but the vast majority of the time you should leave this checked.

The third box is called Resize, and it controls whether the user can change the size of the window by dragging the lower right corner. For this application, we’re going to disable resizing of this window, so uncheck Resize. You’ll learn how to handle controls in windows that resize later in the book.

Leave the rest of the attributes unchanged for now. The class that represents windows is a very flexible class, and the other attributes give you a tremendous amount of control over the appearance of your application, but for most windows, the default settings are what you want.

Now, press ⌘3 to bring up the size inspector (Figure 3-8). This is where we can set the size and size-related attributes of the selected object. As you saw in the last chapter, objects can be moved and resized using the mouse, but this inspector gives you more precise control over the size and position of an object.

Figure 3-8. The size inspector allows you to set the size and position of an object with pixel-level precision. This is the size inspector for a window; the size inspector for other objects looks a little different. This is the Leopard version. Appearance differs slightly in Snow Leopard.

Set the width of your window to 480 pixels, and the height to 130 pixels. Set the x value of the window to 100, which indicates that we want the window’s initial position to be on the left side of the screen.

Return Main Page Previous Page Next Page

®Online Book Reader