How to add "more" button to Tab Bar?

13,427

Solution 1

You do not have to manually create a "More..." button. Simply add all of the View Controllers that you need to the Tab Bar Controller and it will handle the rest.

Solution 2

You can set the last bar button as a "More" button even when there are only three tabs. The initialisation code for that tab bar item would be:

self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMore tag:0];

Solution 3

Make your names shorter, or don't use a tab bar. You will have five or six view controllers, but only want two will be accessible at any given time? If two thirds of your views will be in the "more" list, why not just display all of them in a list? Then you could reclaim the space at the bottom, and no view would require have extra taps.

If you really want to do this, you should write a replacement for UITabBarController. I looked through UIKit, and even tried swizzling -_viewControllersInTabBar, but the five button limit is assumed in several places in UITabBarController, so you're better off writing your own.

You may have noticed that some iPad applications, like YouTube, have more than five tab bar items: alt text
(source: apple.com)

How can this be, if UITabBarController is so obsessed with having no more than five view controllers? Maybe Apple added some kind of private method to UITabBarController in the 3.2 SDK that could help you. Maybe it's called something like -_setMaximumNumberOfItems: and maybe it sets an NSUInteger instance variable called _maxItems. If Apple did add such a private method, you would still need to wait for an iPhone-compatible version of 3.2 to be released, and even then, using private methods is Bad.

Change your tabs names. Not that big of a deal.

Share:
13,427
Graeme
Author by

Graeme

Updated on June 14, 2022

Comments

  • Graeme
    Graeme almost 2 years

    My iPhone app has a tab bar controller at the bottom of the view - and at the moment I have three buttons on it. However, I want to add more, but to do so I need to turn the last of the three buttons into a "More..." button, because otherwise the text on the other buttons runs into each other.

    I know that if you have over 5 buttons in the tab bar, then it automatically creates a more button - but is there a way to manually invoke this with the editing capabilities?

    Thanks.

  • Graeme
    Graeme over 14 years
    MMMM I realised that, but I only want 3 buttons to show, one of which is the more button. The rest I want to only show when the user presses more, hence why I need to somehow manually implement it.
  • gerry3
    gerry3 over 14 years
    How many tabs do you have total? Why require extra taps for no reason? You could make your own "More" tab and then have it display a navigation controller and table view with the other options.
  • Graeme
    Graeme over 14 years
    I will have five or six in total, but they each have long names and they look squished when they all display at once. I thought that might be the only way - I was hoping I could somehow invoke the more button rather than having to manually make all that.