views:

770

answers:

4

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.

+3  A: 

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.

gerry3
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.
Graeme
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.
gerry3
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.
Graeme
+1  A: 

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

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.

lemnar
+1  A: 

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

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

vidya
A: 

hi lemnar , so it is not possible to even make 6 view tab bar application ?

even if the name of each is super short

let's say something like that

red red red red red

instead of yellow yellow yellow yellow yellow

AlsonToh-SG