Code to create “Tabs in Swift 3 (IOS)”

Tabs in Swift3

 

Create three Viewcontrollers(VC) and project 2nd and 3rd VCs as tabs on the first view controller

//  VC1.swift

//  tab

//

//  Created by Deepak Anil Shakyavanshi on 10/01/17.

//  Copyright © 2017 Deepak Anil Shakyavanshi. All rights reserved.

//

import UIKit

class VC1: UIViewController ,CAPSPageMenuDelegate {

        

        var aPageMenu : CAPSPageMenu?

        var controllerArray : [UIViewController] = []

        override func viewDidLoad() {

 

            super.viewDidLoad()

         // var controllerArray : [UIViewController] = []

 

        }

    override func viewDidAppear(_ animated: Bool) {

        

         var controllerArray : [UIViewController] = []

        

        let scheduleVC = self.storyboard!.instantiateViewController(withIdentifier: “VC2”)

        //(optional)scheduleVC.title = “VC 2”

        controllerArray.append(scheduleVC)

        

        let Viewc3 = self.storyboard!.instantiateViewController(withIdentifier: “VC3”)

        //(optional)scheduleVC.title = “VC 3”

        controllerArray.append(Viewc3)

        

        let menuParam : [CAPSPageMenuOption] = [

            .menuItemSeparatorWidth(1.0),

            .menuMargin(20.0),

            .menuHeight(40.0),

            .useMenuLikeSegmentedControl(true),

            .menuItemSeparatorRoundEdges(true),

            .selectionIndicatorHeight(2.0),

            .menuItemSeparatorPercentageHeight(0.5)

        ]

 

aPageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x:0.0, y:64.0, width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height-64.0), pageMenuOptions: menuParam)

 

        aPageMenu?.delegate = self

        //self.addChildViewController(aPageMenu!)

        self.view.addSubview(aPageMenu!.view)

        //aPageMenu!.didMove(toParentViewController: self)

    }    

}

 

Image Courtesy:

Figures: google.com/images


Written and submitted by: Niket Singh

Leave a Reply

Your email address will not be published. Required fields are marked *