Changing Calculator’s Application Icon

To show you how to change the application icon for our Calculator, we’ll assume that you’ve saved a copy of the file AppIcon.icns in your ~/Calculator folder as we described in the previous section. (If you haven’t done this, copy the file with this name from /Developer/Examples/AppKit/DotView or some other AppKit example). Then we’ll tell PB to use an image from AppIcon.icns for our Calculator’s application icon. When the Calculator program is compiled, the icon’s image will automatically be included in the Calculator’s NSBundle folder.

  1. Back in PB with Calculator.pbproj, choose Project Add Files.

  2. Select the AppIcon.icns file, as shown in Figure 6-21, and click the Open button.

Adding the AppIcon.icns file to the Calculator project

Figure 6-21. Adding the AppIcon.icns file to the Calculator project

As shown in Figure 6-22, PB will prompt you as to whether or not you wish to copy the items that you have just selected (e.g., the AppIcon.icns file) into the destination group’s folder. The setting of this checkbox does not matter, because you already copied the AppIcon.icns file into your project directory.

Option to copy AppIcon.icns into project directory

Figure 6-22. Option to copy AppIcon.icns into project directory

  1. Do not change any settings in the newly dropped sheet; simply click the Add button.

The AppIcon.icns file should now show up in the Groups & Files pane (Resources group) in the main PB window. We like keeping our files well organized in this pane, so we’ll create a new group called “Images” in which we’ll store our icons. Grouping has no real effect on your application, but it does make it easier to find files in large projects.

  1. Choose PB’s Project New Group command and rename “New Group” as “Images”.

  2. Drag the AppIcon.icns file into the new Images group in PB’s Groups & Files pane and drop it when the little gray arrow turns into your highlight color.

Now we’ll make the icon we just created be the application icon for the Calculator application:

  1. Select PB’s vertical Targets tab (at the center, near the bottom of PB’s main window).

  2. Make sure that Development is checked in the Build Styles pane (it should be already).

  3. Select Calculator in the Targets area, and another set of tabs will appear on the right.

  4. Select the newly appeared Applications Settings tab and focus on the Icon section, as shown in Figure 6-23.

Setting the Application icon for our Calculator

Figure 6-23. Setting the Application icon for our Calculator

  1. Enter the filename AppIcon.icns in the “Icon file:” white text field area, as shown in Figure 6-23, and hit Return.

  2. Build and run your Calculator application in PB. As usual, save all files before building.

  3. With the application running, choose Calculator About Calculator. You should see something similar to the screen shot in Figure 6-24 . Note that there is no icon in the About box, but we’ll change that in the next section.

The running Calculator application with customized About box (no icon yet)

Figure 6-24. The running Calculator application with customized About box (no icon yet)

Although it doesn’t always work right away, you should eventually see the application icon in your Dock to represent the running Calculator application (see Figure 6-24). You should also see it in the Finder when the Calculator application is selected in the ~/Calculator/build/ folder. If your application icon doesn’t show up right away, try logging out and then logging back in — that worked for us.

  1. Choose Calculator Quit Calculator.

Making the New Icon Appear in the About Box

When we created our new About box in AboutPanel.nib , we left a space for the new application icon in the upper-right corner. In the following steps, we will add an NSImageView object in our About box to help display our new application icon:

  1. Back in IB, be sure that AboutPanel.nib is the active nib by clicking in its Nib File window.

  2. Click the Cocoa-Other button, which should be the third one from the left in IB’s Palettes window toolbar.

  3. Add an NSImageView object to the About box by dragging its icon from the Cocoa-Other palette and dropping it into the top-right area of the About box.

  4. Click the Images tab in the AboutPanel.nib window. Note that there are two copies of the icon we created, one labeled “AppIcon” and the other “NSApplicationIcon”.

  5. Add our new application icon to the new NSImageView by dragging the AppIcon-labeled icon from the Images pane in the AboutPanel.nib window and dropping it on the NSImageView in the About box. See Figure 6-25 for the result (your icon won’t look exactly like this screen shot yet).

Adding our newly created application icon to the About box

Figure 6-25. Adding our newly created application icon to the About box

  1. Remove the border around the NSImageView object in the About box by clicking the icon on the left in the Border area of the NSImageView Info dialog.)

  2. Make sure that the image alignment is centered and scaling is set to “Proportionally” in the NSImageView inspector. The result is shown in Figure 6-25.

  3. Back in PB, build and run your project. Save all files when prompted.

  4. Choose the Calculator About Calculator menu command; you should see your custom application icon, as shown in Figure 6-26.

The running Calculator application with the application icon displayed in the About box

Figure 6-26. The running Calculator application with the application icon displayed in the About box

  1. Choose Calculator Quit Calculator.

There is no limit to the number of images that you can add to your application. To add an image to your project, simply drag the GIF, JPEG, or TIFF icon for that image file from your Finder window and drop it into your application’s nib window in IB or in the main window in PB. Images that are stored in one nib cannot easily be used by objects in other nibs. For this reason, it is usually better to store images in the project directory rather than in a nib.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.59