Xcode Interface Builder Tips

A couple of quick tips when using Interface Builder that I picked up whilst watching the WWDC 2013 videos. It turns out that whilst these are new to me they are not actually new. I do not know when these were introduced but they work fine in the current public release of Xcode (v4.6.3 at time of writing).

Selecting An Object

The first tip addresses an annoying situation when you are trying to select a specific object in the view hierarchy. Consider a table view controller containing a prototype cell view which itself contains a number of labels:

It can be tricky to click-on a specific object such as the table view cell or the table view without getting one of the UILabel objects by mistake. One option is to find the object you want in the document navigator window:

However a much easier way is to control-shift click in the scene. This displays a popup window with the full view hierarchy for wherever you click. For example, in the screenshot below I control-shift clicked with the mouse pointer over the “Country” UILabel:

It is now simple to select the table view cell or the table view without resorting to the document browser.

Viewing Layout Metrics

The second quick tip allows you to view the relative spacing and positioning of a view. With a view selected, press the Option key and move the mouse pointer over the scene in Interface Builder. As you move around a set of guides are displayed showing the number of pixels from the selected view to the view you are currently hovering over. For example, with the Country UILabel selected and the pointer over the table view the following is displayed:

Useful for those situations when you want to align and carefully position a number of views.