In this recipe, we will learn how to add and use toolbars within our application.
In this recipe, we will discuss the usage of the Toolbar
object and how we can use the associated properties to display an animated progress bar.
In order to see how this can be achieved, we need to modify our ViewObjectsExample application that we created in the previous recipe. Perform the following steps to do so:
ViewObjectsExample.xcodeproj
project file.ViewController.xib
file from the project navigator window.Flexible Space Bar Button Item
object to the toolbar to the right of the Fade In button.Flexible Space Bar Button Item
object.btnFadeIn
and btnFadeOut
.viewFadeIn
and viewFadeOut
.Our next step is to create the code functionality that will be responsible for updating the label to display what button was pressed within the toolbar:
ViewController.m
implementation file from the project navigator.viewFadeIn
and viewFadeOut
methods, as shown in the following code snippet:- (IBAction)viewFadeIn:(UIBarButtonItem *)sender { lblInfo.text = @"Fade In button clicked."; } - (IBAction)viewFadeOut:(UIBarButtonItem *)sender { lblInfo.text = @"Fade Out button clicked."; }
When the compilation completes, the iOS Simulator will appear. Tap on both of the toolbar buttons to see the label update based on which button has been clicked.
The UIToolbar
object is used to hold items relating to the UIBarButtonItem
object type. These types of objects are special kinds of buttons and spacers. A UIBarButtonItem
object can be system defined or custom type, and can use any of the predefined types as listed in the Identifier attribute within Interface Builder and provides a specific icon to the button.
The UIBarButtonItem
objects can also be customized to contain an image to make your application more
professional and visually intuitive. This can be achieved by using the Image attribute within Interface Builder.