How to create a left-arrow button on a Toolbar on iPhone/iPad?

iOSiPhone/iPadMobile Development

To create a button on toolbar we'll need to use two different components of iOS and another image that is a back arrow. Before that let's see what those components are

  • Toolbar − Toolbar is a native iOS component that is used to display items or toolbar on the bottom of screen.

  • Bar Button item − It is a button that's usually created on a Toolbar or a navigation bar.

When a toolbar is created using storyboard, it comes with a Bar button item.

Let's start by creating a new project, in the main.storyboard give some background color to the only viewController we have.

From the object library drag and drop a toolbar to the bottom on that view Controller. It will automatically create a bar button too.

Select the toolbar, give it a bottom, left and right constraint of 0 and an height of 50.

Download a back image and select the bar button item on the toolbar. Select the image from attribute inspector. From the attribute inspector you can select properties like Image, title, tint color etc.

Now run the project and it looks like −

The toolbar automatically arranges items and give them equal spaces depending upon the number of items.

raja
Published on 22-Jan-2019 12:07:40
Advertisements