90

Tab Bar Controller iOS Tutorial

 6 years ago
source link: https://www.tuicool.com/articles/hit/NZZbaan
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This tab bar interface displays tabs at the bottom of the window for selecting different views. In this Tutorial a Tab Bar Controller will be created and by default two Tab Bar Items will be included. The third Tab Bar Item will be added using the Storyboard. This tutorial is made with Xcode 10 and built for iOS 12.

Open Xcode and create a new Tapped App.

vUjIBbA.png!web

For product name, use IOS12TabBarControllerTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next.

IrQf63e.png!web

For the Tab Bar items some custom images will be used.Download the images, unzip them and add the images to the Assets Library. Go to the Storyboard. In the Document Outline select the First Bar button Item in the First Scene and go to the Attribute Inspector. In the Bar Items section change the title to "Red" and select the book image.

vIB77na.png!web

Repeat this step for the Second Bar Item of the Second View Controller. Name it "Blue" and select the clock image.

rYjMf2A.png!web

Select to the Red View and change the Background to red using the Attributes Inspector. In the blue view change the Background to blue. Also remove the Labels inside the view.

ryeqAjv.png!web

The Storyboard should now look like this.

RjIbEfm.png!web

Build and Runthe project, and change views by clicking the Tab Bar Items.

ryemyqv.png!web

Next, we will add another Tab Bar Item inside the Storyboard. Drag a View Controller from the Object Library to the Scene. Select the View Controller and go to the Attribute Inspector. Change the Background color to Green. Next Ctrl and Drag from inside the Tab Bar Controller to the newly created View Controller and select "view controllers" in the Relationship Segue section.

2MZvqeU.png!web

In the Document Outline select the Tab Bar Item in the Item Scene and Go to The Attribute Inspector. In the Bar Items section change the title to "Green" and select the crown image.

Bb2Iv2e.png!web

Build and Runthe project, the 3 Tab Bar Items will be visible. By clicking the Icons the Views will change.

2eInMbi.png!web

You can download the source code of the IOS12TabBarControllerTutorial at the ioscreator repository on  Github .


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK