How do I add using the InterfaceBuilder?
If you already have a UINavigationController, it's preferable to use its built-in toolbar.
In Interface Builder, check "Shows Toolbar" in your Navigation Controller's properties, and then use the toolbarItems
attribute in your view controllers to populate the toolbar:
self.toolbarItems = [NSArray arrayWithObjects:...];
If you don't have a UINavigationController, you can drag a UIToolbar in from the library. I usually set its frame in the nib using the snap to guides feature. Then you can set the items with the method that @Can Berk Güder gives. Using UIBarButtonSystemItemFlexibleSpace
and/or UIBarButtonSystemItemFixedSpace
you can get a pretty good arrangement of buttons.
If you're doing it this way, just declare a UIToolbar* toolbar
and set @property (nonatomic, retain) IBOutlet UIToolbar* toolbar
in the interface of your view controller. In the implementation just @synthesize toolbar;
. You can set the items in viewDidLoad
and link the toolbar to your nib file by adding a new referencing outlet to 'toolbar' in File's Owner.