Menu from tab bar in storyboarding Menu from tab bar in storyboarding xcode xcode

Menu from tab bar in storyboarding


I would recommend you do so:

First, you should think of all the tab types that could be in tab bar. On your screenshot there are tabs, that present controller, and tab, that presents menu. So we could create enum with all these types:

enum TabType {    case controller    case menu}

After that you can store array of tab types in order they are shown in tab bar, for your screenshot like so

let tabTypes: [TabType] = [.controller, .controller, .controller, .controller, .menu]

Then you should implement UITabBarControllerDelegate's func tabBarController(_:, shouldSelect:) -> Bool method, which returns true if tab bar is allowed to select the passed controller, and false otherwise.

If you return true than all other work (like presenting view controller and other stuff) tab bar controller will do for you.

In your case you want to execute custom action on tab click, so you should return false. Before returning you should present your menu.

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {    if let index = tabBarController.viewControllers?.index(of: viewController),        index < tabBarTypes.count {        let type = tabBarTypes[index]        switch type {        case .menu:            // perform your menu presenting here            return false        case .controller:            // do nothing, just return true, tab bar will do all work for you            return true        }    }    return true}

In this implementation you can easily change tab types order or add some another tab type and handle it appropriate.


Its not good UI but although if you want.

First You have to implement delegate method of UITabbarControllerDelegate as below

func tabBarController(_ tabBarController: UITabBarController, shouldSelect  viewController: UIViewController) -> Bool {    if viewController.classForCoder == moreViewController.self    {           let popvc = MoreSubMenuViews(nibName: "MoreSubMenuViews", bundle: Bundle.main)        self.addChildViewController(popvc)        let tabbarHeight = tabBar.frame.height        let estimatedWidth:CGFloat = 200.0        let estimatedHeight:CGFloat = 300.0        popvc.view.frame = CGRect(x:self.view.frame.width - estimatedWidth, y: self.view.frame.height - estimatedHeight - tabbarHeight, width: estimatedWidth, height: estimatedHeight)        self.view.addSubview(popvc.view)        popvc.didMove(toParentViewController: self)        print("sorry stop here")        return true // if you want not to select return false here    }else{        //remove popup logic here if opened        return true    }} 

Here moreViewController is last tab controller & MoreSubMenuViews is nib/xib file which contains buttons shown in you image.


Instead of showing a menu, you could use a scrollable tabs view for a better UI. If you prefer using a library, here's a simple scrollable tab-bar you could implement.