Interface Builder tips
Posted on May 21, 2008 at 9:00 am by Late Night Coder
Xcode 3 was a pretty significant upgrade, and included some desperately needed improvements to Interface Builder. Now, although the new version of Interface Builder is significantly improved, it still suffers from some eccentricities and a lack of good example-driven documentation. It’s an amazingly powerful tool, but a lot of its features can be somewhat hard to discover without help. This post contains a few things I’ve discovered about Interface Builder over time that I’ve found really useful.
Vertical and horizontal snap alignment
Holding SHIFT while dragging components in Interface Builder will cause them to “snap” to virtual vertical or horizontal guides. Unfortunately, this works in addition to the automated Aqua guides attached to components and containers, which means you can get some funky snapping behavior using SHIFT dragging in a crowded window. Even more unfortunately, in Xcode 3 they removed the ability to turn off Aqua guides.
Embedding and unembedding components
This is a new feature in Xcode 3. In prior versions the only way of unembedding a component was to cut it or delete it. In Xcode 3, clicking and holding on a component for a moment (without moving the mouse) will unembed the component. You can then drag the component within another view or window to embed it as a child of the new container.
Pixel exact positioning
A selected component can be moved one pixel at a time using the arrow keys. This is very useful for precise positioning. Holding SHIFT while pressing the arrow keys moves a component by five pixels.
Position information
Holding OPTION displays position information for a component. This works in many situations including when a component is selected, when a component is being dragged, and when a component is being resized. It also works when hovering over components. Combining these, if you select one component, and then hover another component with OPTION held down, it shows you relative position information.
Copying components
In typical Mac OS X fashion, holding OPTION before dragging a component will cause it to be copied instead of moved. If you drop the component over another view the new copy will be embedded and made a child of that view. Note that if you don’t press OPTION before you start dragging the component, pressing it afterwards will show position information as described above.
Remembering a user’s window size and position
To enable user changes to a window’s size and position to be saved and restored automatically every time they launch the application you simply need to set the Frame name attribute to a unique name in the Window Attributes inspector panel.
Naming components in the NIB window
Components in the NIB window are, by default, named based on their type. This quickly gets confusing as the number of components in the NIB grows. To use a custom name, select the component, and then set the Name attribute in the Interface Builder Identity section of the Identity tab.
► Post a Comment