UITabBar Showing More Icons Instead of “More” Opti

2020-05-02 05:04发布

问题:

I'm currently attempting to use the UITabBar for an iOS app that contains 7 tabBar Items.

When I use the storyboard, I am able to achieve all 7 tabBarItems. When I programmatically add the tabBarItems, It forces a "More" Button to access the other tabBarItems.

Is there a way programmatically keep all the 7 tabBarItems as when I am manually create the UITabBar?

The Code that I'm using to build the uitabbar in my appdelegate.m

  self.tabBarController = [[UITabBarController alloc] init];
  FirstViewController *firstVC = [[FirstViewController alloc] init];
  SecondViewController *secondVC = [[SecondViewController alloc] init];
  ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
  FourthViewController *fourthVC = [[FourthViewController alloc] init];
  FifthViewController *fifthVC = [[FifthViewController alloc] init];
  SixthViewController *sixthVC = [[SixthViewController alloc] init];
  SeventhViewController *seventhVC = [[SeventhViewController alloc] init];

  NSArray *controllers = @[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC, seventhVC];

  self.tabBarController.viewControllers = controllers;
  self.window.rootViewController = self.tabBarController;
  [_window addSubview:_tabBarController.view];

回答1:

By design you are limited to 5, from apple docs

If you add more than five items to the viewControllers property, the tab bar controller automatically inserts a special view controller (called the More view controller) to handle the display of the additional items. The More view controller provides a custom interface that lists the additional view controllers in a table, which can expand to accommodate any number of view controllers. The More view controller cannot be customized or selected and does not appear in any of the view controller lists managed by the tab bar controller. It appears automatically when it is needed and is separate from your custom content. You can get a reference to it though by accessing the moreNavigationController property of UITabBarController.

It just not recommended , but if you insist you will need to use a library or perhaps use a tool bar and add many UIBarButtonItems to it.