Swift Tutorial : How to Create a CustomTabbar or Side Menu with One Common Code Structure?


CustomTabbar is a common task for iOS App Developers. The look and feel of the standard tabbar in iOS 7+ are normal and good, but it doesn’t suit every time into the app’s design.

Nowadays, customizing tabbar is much easier than it was before, as Apple offers multiple simple ways to change the design of the tabbar: changing the background images, tint color, icons or text attributes offer many different ways to create a unique tabbar.


It is quite difficult to manage UI/UX. But with CustomTabbar, iOS developers can easily manage UI/UX. CustomTabbar is easy to manage than default tab bar.

Step 1: How to integrate ATTabbar.swift?

It’s simple, you just have to drag and drop “ATTabbar.swift” class in your project.

Step 2: How to Use ATTabbar.swift?

2.1 First, you have to create a “ViewController.swift” class

2.2 Now, assign it to a UIViewController in Storyboard and assign class ViewController (refer given image.)

How to Use ATTabbar.swift?

2.3 After that, you have to add “Container” in ViewController in

@IBOutlet weak var container: UIView!

Step 3: In the next step, you have to define view controller and a destination identifier in “ViewController.swift”

var destinationViewController:UIViewController!

var oldViewController:UIViewController!
var _viewControllersByIdentifier:NSMutableDictionary!
var destinationIdentifier:NSString!

Step 4:

In this step, we are adding four buttons in the bottom of UIViewController and give them a tag.

Swift Tutorial : How to Create a CustomTabbar

Step 5:

Now, create 4 new ViewControllers and name them “FirstViewController.swift”, “SecondViewController.swift”, “ThirdViewController.swift”, “FourthViewController.swift” and assign all them in storyboard as we have done with ViewController.

Swift Tutorial : How to Create a Side Menu

Step 6:

In this step, you have to connect all view controllers (“FirstViewController.swift”, “SecondViewController.swift”, “ThirdViewController.swift”, “FourthViewController.swift”) to “Container” in ViewController by custom Segue.

Side Menu with One Common Code Structure

Step 7:

Now, add identifiers (i.e. FirstSegue, SecondSegue, ThirdSegue, FourthSegue) for all view controllers and assign class“ATTabbar” for all.

Create a CustomTabbar in Swift


Side Menu with One Common Code Structure in Swift

Step 8:

After that, you have to create an action for tab bar button in “ViewController.swift” and connect it to all 4 buttons shown at the bottom.

//MARK:- Action For Tab Change

@IBAction func btnTabChangedClicked(sender: AnyObject) {
        let button = sender as! UIButton
        UIView.animate(withDuration: 0.5, animations: {
            self.sliderView.center = button.center
        switch button.tag {
        case 1:
            self.performSegue(withIdentifier: "FirstSegue", sender: nil)
        case 2:
            self.performSegue(withIdentifier: "SecondSegue", sender: nil)
        case 3:
            self.performSegue(withIdentifier: "ThirdSegue", sender: nil)
        case 4:
            self.performSegue(withIdentifier: "FourthSegue", sender: nil)
            self.performSegue(withIdentifier: "FirstSegue", sender: nil)

// MARK: – Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
        self.oldViewController = self.destinationViewController;
        if((_viewControllersByIdentifier.object(forKey: segue.identifier!)) == nil){
            _viewControllersByIdentifier.setObject(segue.destination, forKey: segue.identifier! as NSCopying)
        self.destinationIdentifier = segue.identifier! as NSString;
        self.destinationViewController = _viewControllersByIdentifier.object(forKey: self.destinationIdentifier) as UIViewController;

Step 9:

To load first tab ViewController, write below code in ‘ViewController.Swift’

override func viewDidLoad() {
        self.sliderView.layer.cornerRadius = 20
        _viewControllersByIdentifier = NSMutableDictionary()
        if(self.children.count < 1){
            self.performSegue(withIdentifier: "FirstSegue", sender: nil)


Create a CustomTabbar or Side Menu

You can directly download the source code by clicking the following button.

Hope, you found this blog helpful to create CustomTabbar or side menu with one common code structure. Let us know if you have any queries or concern regarding CustomTabbar in swift.

From January 2016, we have started Swift App Development for all the new iOS development projects and we recommend our clients to hire swift developer for iPhone and iPad app projects. We as a front runner in the industry would recommend you for your business to deploy your own swift application with less code at iTunes.

You may also like,

This page was last edited on May 22nd, 2020, at 0:59.


Have an App Idea?

Get your free consultation now

Get Your Free Quote