Historical content: I wrote this article over 8 years ago on 2009-01-10. You are viewing an archived post from my old WordPress blog. The archive contains over 1,600 articles written over a ten year period. The formatting and contents of the posts may not display perfectly.
Apple recommends that you design your application with Interface Builder whenever possible. However, you may need to create controls in code when the makeup of your UI is not fully known until runtime. This sample shows both approaches as it gives you an idea of the "magic" that goes on behind the scenes in Interface Builder: creating the standard UI elements, affecting their behavior and attributes, and setting their target/action connections. As an added bonus, a special Objective-C category is introduced to show how to un-select all segments of an NSSegmentedControl.