目标C - 如何在iOS中创建具有多个选项卡的Scrollable选项卡栏

问题描述 投票:0回答:1
  1. 在编程方面,我创建了动态选项卡到下面的代码。

NSMutableArray * dataArray = [[NSMutableArray alloc] init];

  UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main"
            bundle:nil];
  BasicIn *viewController1=[storyboard instantiateViewControllerWithIdentifier:@"BasicInfo"];
  viewController1.tabBarItem.image=[UIImage imageNamed:@"contactTab.png"];
  viewController1.tabBarItem.title=@"Basic Info";
  [dataArray addObject: viewController1];

  UIStoryboard *storyboard1=[UIStoryboard storyboardWithName:@"Main"
            bundle:nil];
  AddImageVC *viewController2=[storyboard1 instantiateViewControllerWithIdentifier:@"AddImageVC"];
  viewController2.tabBarItem.image=[UIImage imageNamed:@"planTab.png"];
  viewController2.tabBarItem.title=@"Images";
  [dataArray addObject:viewController2];

   UITabBarController  *myTabBarController = [[UITabBarController alloc] init];
   self.myTabBarController.viewControllers =dataArray;
   [self.view addSubview:[self.myTabBarController view]];

    UIColor *appTintColor=[UIColor colorWithRed:19.0/255 green:89.0/255 blue:234.0/255 alpha:1.0];

    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont
                                                                                   fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                            NSForegroundColorAttributeName : appTintColor
                                                            }forState:UIControlStateSelected];        


Now It`s created a normal tab bar function.you can create dynamic tabs in tab bar controller with this code, without using any 3 party framework.
objective-c uiscrollview uitabbarcontroller
1个回答
0
投票

不,UITabBarController不能做可滚动的标签栏。它只能处理1-5个条形按钮,之后您将获得一个更多按钮作为访问其他按钮的最后一个元素。

文件说:

如果向选项卡栏控制器添加六个或更多自定义视图控制器,则选项卡栏控制器仅显示前四个项目以及选项卡栏上的标准更多项目。

Read more about UITabBarController here

也就是说,您可以随时添加自己的自定义UI组件来完成工作。根据您的具体要求,可能不会那么困难。

© www.soinside.com 2019 - 2024. All rights reserved.