iOS – 标签栏
标签栏的使用
它通常用于在同一视图内的各种子任务、视图或模型之间切换。
标签栏的示例如下所示。

重要属性
- 背景图片
- 项目
- 所选项目
示例代码和步骤
步骤 1 − 创建一个新项目并选择 Tabbed Application 而不是基于视图的应用程序,然后单击 next, 给出项目名称并选择 create.
步骤 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 − 当我们运行应用程序时,我们将得到以下输出 −
