IOS選項卡欄的使用

它一般用於在同一視圖中各個子任務、 視圖或的模型之間切換。

選項卡欄的示例如下所示:

tabBar

重要的屬性

  • backgroundImage
  • items
  • selectedItem

示例代碼和步驟

1. 創建一個新的專案,選擇  Tabbed Application 替代視圖應用程式 ,點擊下一步, 輸入專案名稱和選擇 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. 運行應用程式,得到如下結果:

tabBarOutput