通常用于在同一视图中的各种子任务,视图或模型之间切换。

标签栏的如下所示。

iOS Tutorial

Tab bar - 重要属性

  • backgroundImage
  • items
  • selectedItem

Tab bar - 示例代码

步骤1 - 创建一个新项目,然后选择 Tabbed Application 而不是基于View的应用程序,然后单击 next ,指定项目名称并选择创建。

步骤2 - 默认情况下,这里创建了两个视图控制器,并且在应用程序中添加了标签栏。

步骤3 -  AppDelegate.m didFinishLaunchingWithOptions 方法如下-

- (BOOL)application:(UIApplication *)application 
   didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] 
   bounds]];
   
   //Override point for customization after application launch.
   UIViewController *viewController1 = [[FirstViewController alloc] 
   initWithNibName:@"FirstViewController" bundle:nil];
   UIViewController *viewController2 = [[SecondViewController alloc] 
   initWithNibName:@"SecondViewController" bundle:nil];
   self.tabBarController = [[UITabBarController alloc] init];
   self.tabBarController.viewControllers = @[viewController1 
   viewController2];
   self.window.rootViewController = self.tabBarController;
   [self.window makeKeyAndVisible];
   return YES;
}

步骤4 - 在这里,分配了两个视图控制器,并将其作为我们的标签栏控制器的视图控制器。

步骤5 - 运行应用程序时,将获得以下输出-

iOS Tutorial

参考链接

https://www.learnfk.com/ios/ios-ui-elements-tab-bar.html