How to add “more” button to Tab Bar?

不想你离开。 提交于 2019-12-09 01:45:52

问题


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.


回答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.




回答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];



回答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:
(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.




回答4:


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



来源:https://stackoverflow.com/questions/2046686/how-to-add-more-button-to-tab-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!