!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> » Musings on the Sometimes Maligned Interface Builder -- Mobile Perspectives

Musings on the Sometimes Maligned Interface Builder

By deans ~ March 31st, 2009. Filed under: Resources.

We all know Interface Builder (IB) as the visual design tool that some of use to lay out UIs for iPhones / iPod Touches.  When I was trying to figure out how to use it, I encountered a great deal of commentary both positive, and negative.  While there will always be those who prefer to do everything programmatically, I’m one of the lazy ones who appreciates tools that let me accomplish my tasks without writing heaps of potentially buggy code.

IB lets me position my controls interactively, and it provides somewhat straightforward hooks for connecting my program to the new controls.  One of the big complaints that I noticed, and one that frustrated me a bit, at least at first, was that IB doesn’t provide full access to all of the settings on the controls that it specifies.  The specific example for me was setting the font for the Title text for the regular "Round Rect Button."  Support for this operation is clearly evident via the "setfont:" method specified in the class header file, but I couldn’t find any way to get at the method through the IB Attributes Inspector.

As suggested above, I’m pretty lazy, so I didn’t want to abandon IB just to change the font face and size, then a solution appeared.  I simply established an outlet to the specific button:

@interface ButtonTestViewController : UIViewController {

IBOutlet UIButton *theButton;

and wrote the following code:

UIFont *theFont = [UIFont boldSystemFontOfSize:30];
[theButton setFont:theFont];
CGSize tOff = CGSizeMake(2.0,2.0);
[theButton setTitleShadowOffset:tOff];

For what it’s worth, my situation was such that I was able to put the code to set the button in the viewDidLoad method.

One other thing to keep in mind when you’re loading your application from a nib, the ViewController’s initWithCoder is the initialization method that gets called.  Thanks to Jeff LaMarche for the explanation of initializers in his response to this question.

Unless you just love writing and maintaining UI code, I strongly urge you to take a careful look at IB.  I’ll continue to use it whenever I can.

Technorati Tags:  , , ,

Comments are closed.