blog posts

Learn the UI toolbar in iOS in simple language

In this section, we will get acquainted with the iOS toolbar in swift with an example. We also learn how to use the ios toolbar in the swift app to display several buttons at the bottom of the screen.

IOS UI toolbar

IOS; The ui toolbar control is displayed at the bottom of the app screen and contains a button or more called toolbar items. Generally; Buttons (toolbar items) are used to perform actions related to running content; For example, add items, delete items, and..

The toolbar in iOS apps is similar to the following.

C: \ Users \ mohammad \ Downloads \ go (16) .png

We can use toolbars in our iOS apps by adding a UIToolbar class reference.

Now with an example of using swift, we see how to use the UI toolbar in our iOS apps.

Create iOS toolbar app in swift

To create a new project in Xcode on iOS, open Xcode from the application folder list. After opening Xcode, the welcome window will open as shown below. In the Welcome window, click on the second option, “Create a new Xcode Project”; Click (create a new Xcode Project) or select the File New Project path.

C: \ Users \ mohammad \ Desktop \ open-xcode-to-create-new-ios-app-using-xcode (1) .pngAfter selecting “Create a new Xcode project”, a new window will open in which we must select our template.

The new Xcode window includes several built-in application templates to implement the usual type of iOS apps, such as page-based apps, tab-based apps, games, spreadsheet apps, and more. These templates have a preset interface and source code files.

In the iOS toolbar,

for example, we have the most basic pattern of the app, which is “demo only”; We will use. To select this item, go to the iOS section on the left, select the application from the select section, and in the main part of the window that opens, select “single view application” and click on the next button, as shown below. .

C: \ Users \ mohammad \ Desktop \ ios-swift-select-single-view-application-in-xcode (1) .png

After clicking Next, we will see a window like the one below, in this case we have to mention the project name and other details for our program.

Product name: “UIToolbar”

The name we enter in the Product Name section is used for the project and application.

Organization name: “Tutlane”

You can enter the name of the organization or your name in this field; Of course you can leave that section blank.

Organization Identifier: com.developersocociety

If you do not have an enterprise ID, enter com.example.

Bundle Identifier: This section is automatically generated based on the terms we entered in the product name and organization ID.

Language: “Swift”

Select the language type “Swift” because we want to develop applications using swift.

Universal (devices): “Universal”

Select the Devices option as Universal This means that this app is for all Apple devices; If you need to run the app for iPad only, you can select the iPad option to restrict your app to running only on iPad devices.

Use core Data: Not selected

This option is used for database operations. Select this option if you are doing any database-related operations in your application, otherwise do not select this option.

Include Unit Test: Not selected

If you need unit tests for your application, select this option otherwise leave it unselected.

Includes UI tests: not selected

Select this option if you need UI tests for your application, otherwise do not select it.

After completing the options, click the Next button as shown below.

C: \ Users \ mohammad \ Downloads \ go (17) .png

When we click the Next button; A new window will open in which you must use the location where you want the new project to be saved; Let’s choose. Once you have selected the new project storage location; As shown below; Click the Create button.

C: \ Users \ mohammad \ Downloads \ go (18) .png

After clicking the Create button, Xcode opens and creates a new project. In our project, Main.storyboard and ViewController.swift are the main files used to design the user interface and maintain the source code.

Main.storyboard – which is the visual interface editor and this file is used to design the application interface.

ViewController.swift – which contains the source code of our application and we use this file to write any code related to our application.

Now select the Main.storyboard file in the project, until Xcode opens the visual interface editor as shown below.

C: \ Users \ mohammad \ Downloads \ go (19) .png

Now select the ViewController.swift file in your project, which looks similar to the following:

C: \ Users \ mohammad \ Downloads \ go (20) .png

Add iOS UI controls to the display in swift

We are now adding controls to our application for that library of available objects. The object library appears at the bottom right of Xcode. If you did not find the object library, as shown below; Click the button that is the third button in the library selection bar on the left. (On the other hand, you can select the View Utilities Show Object Library path).

As we have suggested; Our interface is the Main.storyboard file, so open the Main.storyboard file. Now look for the Toolbar in the Object Library in the Filter box and then drag and drop the Toolbar into the ViewController in the Main.storyboard as shown below.

Here we have changed the screen size to “3.5 inch iPhone” to have a better view, if you are satisfied with the size of your simulator; Drop this option.

C: \ Users \ mohammad \ Downloads \ go (21) .png

In the same way as shown below; Drag a label and drop it into ViewController.

C: \ Users \ mohammad \ Downloads \ go (22) .png

Linking UI controls to coding in Swift

Now we establish the connection between the controls and the ViewController code, for this purpose, we click on the Assitant button, which is similar to the following; In the upper right corner is the Xcode toolbar (two intertwined circles).

To map the controls, hold down the Ctrl key on the keyboard and as shown below; Drag the toolbar from the interface and drop it into the ViewController.swift file.

C: \ Users \ mohammad \ Downloads \ go (23) .png

When we have finished the settings; We need to write the custom code in the ViewController.swift file so that the phrases we want are displayed after clicking on the icons; Let’s adjust.

 When we write the functions we want, the ViewController.swift file will look like the following.

import UIKit

class ViewController: UIViewController {

var toolbarHidden: Bool = false

@IBOutlet var toolbar: UIToolbar!

@IButlet var debugLable!

@IBAction func rewindButtonAction (sender: UIBarButtonItem) {

Self.debugLabel.text = “Rewind-Action”


@IBActin func pauseButtonAction (sender: UIBarButtonItem) {

Self.debugLabel.text = “Pause-Action”


@IBAction func forwardButtonAction (sender: UIBarButttonItem) {

Self.debugLabel.text = “Forward-Action”


Override func viewDidLoad () {

Super.didRecieveMemoryWarning ()



Now run the program and check its output. To implement the program, select the required emulator (here we have selected iPhone Six S Plus) and click on the Play button, which is located in the upper left corner of the Xcode toolbar, as shown below.

IOS toolbar output in Swift language

Below you can see the implementation of the iOS toolbar app. Now click on the Play button shown below; Likewise on the button marked pause; backward; Click forward.

C: \ Users \ mohammad \ Downloads \ go (25) .png

This way we can use the ui toolbar in swift applications to take action on the current page; Be done according to our needs.