Online Book Reader

Home Category

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

By Root 1051 0
a bit. You may have noticed when testing your interface that you could make the window so small that not all GUI objects could fit inside. We don’t want to deal with that possibility in this simple application, so we’ll set the window’s current size to be the minimum allowable size. Select your window by clicking in its title bar, then bring up the Size Inspector (⌘3). In the upper part of the inspector window, you’ll see a section labeled Minimum Size. First click on the Has Minimum Size checkbox, then click the Use Current button to make sure the window can’t be resized below its current size. If you test your interface now, you should see that this works.

Now, we want to make sure that most of the boxes in our interface (all except the one containing the text view) will stick to the top edge of the window when resizing, instead of the bottom. Click on the upper left-hand box labeled Basic Information, and you’ll see that the Size Inspector now shows us attributes for this box, including an animated thumbnail display of how it will resize. Next to the animation, inside the Autosizing section, you’ll see a control that resembles a set of crosshairs, with a central black square and some horizontal and vertical red lines, some solid and some dashed (See Figure 4-14).

Figure 4-14. The Autosizing control in the Size Inspector

Basically, the black square represents the selected view. Outside the black square, a solid line indicates a margin that is fixed (relative to the parent view’s boundaries) and will be preserved as the parent view is resized, and a dashed line indicates a margin that is flexible and will automatically change when the parent view is resized. Inside the black square, a solid line indicates a dimension that is flexible and will resize along with the parent, while a dashed line indicates a dimension that is fixed and won’t change. This is one of those things that sounds more confusing that it really is. Trial and error, in combination with the animated preview and the “test interface” feature, will advance your grasp of this more than anything you read in a book.

For each of the upper boxes, you should configure the autosizing control so that the top and left red lines are solid, and all other red lines are dashed. Configure each of those boxes that way, test your interface, and you’ll see as you resize the window that they will stick to the upper left.

The last bit of resizing configuration we want to do is for the box containing the text view, at the bottom of the window. Select the box labeled Notes, and edit the autoresize control so that all the lines are solid. That means that as resizing occurs, this box will retain the same distance to each side of its parent view (the window itself, basically), and will resize itself to match that constraint. Now do the same configuration for the text view itself, contained inside the box, so that it will resize along with the box.

Now you can test your interface, and you should see that the upper boxes hold their positions relative to the upper left corner, while the box containing the text view resizes along with the window. The layout for all our controls and other views is finally complete!

Time for the Controller


Now it’s time to finally bring in the VillainTrackerAppDelegate that we created earlier in this chapter, and make all the necessary connections between it and the views in our window.

Go to the Library window’s search field and type in “object.” One of the search results, titled Object, is a generic object that starts out its life in Interface Builder as an NSObject, but we can easily change it to anything we want. Drag an Object to your main nib window, and then open the Identity Inspector (⌘6). The combo box at the top of this inspector lets you set the class of the selected object. Type in “VillainTrackerAppDelegate,” and the new object you created is now an instance of VillainTrackerAppDelegate. You will even see that the “name” of the object, as shown in the nib window, has magically changed to “App Controller” to reflect

Return Main Page Previous Page Next Page

®Online Book Reader