How to add "more" button to Tab Bar?
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 开发者_JAVA技巧a more button - but is there a way to manually invoke this with the editing capabilities?
Thanks.
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.
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];
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:
(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.
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
精彩评论