Tab Bar Controller Tutorial in iOS8 with Swift

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 created for iOS 8.4 with Xcode 6.4.

Open Xcode and create a new Single View Application. For product name, use IOS8SwifttTabBarControllerTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.

Go to the Storyboard and delete the View Controller from the Scene. Drag a Tab Bar Controller from the object Library to the scene. This Tab Bar Controller has by default 2 items with 2 View Controllers already connected. Delete the ViewController.swift file and create a new file by choosing File -> New -> File. Choose iOS -> Source -> Cocoa Touch Class. Name the Class "ColorController" and make it a Subclass of UITabBarController.

Go Back to the Storyboard. Select the Tab Bar Controller and go to the Identity Inspector. At the Custom Class section change the class to ColorController.

Go to the Attribute Inspector and in the View Controller section appy the "Is Initial View Controller" checkbox.

For the Tab Bar items we will use some custom images. Download the images, unzip them and add the images to the project. In the Document Outline select the Item 1 Bar button Item in the Item 1 Scene and go to the Attribute Inspector. Make the Item a Custom Item and give it a title of "Red" and select the book image.

Repeat this step for Item 2. Name it "Blue" and select the clock image.

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

The Storyboard should now look like this.

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

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 Color Controller to the newly created View Controller and select "view controllers" in the Relationship Segue section.

In the Document Outline select the Tab Bar Item in the Item Scene. Go to The Attribute Inspector and make the Item a Custom Item and give it a title of "Green" and select the crown image. 

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

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