iOS 教程
它一般用于在同一視圖中各個子任務(wù)、 視圖或的模型之間切換。
選項卡欄的示例如下所示:
重要的屬性
示例代碼和步驟
1. 創(chuàng)建一個新的項目,選擇 ?Tabbed Application?替代視圖應(yīng)用程序?,點擊下一步, 輸入項目名稱和選擇?create.
2.?這里默認(rèn)創(chuàng)建兩個視圖控制器和標(biāo)簽欄添加到我們的應(yīng)用程序。
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.?運行應(yīng)用程序,得到如下結(jié)果: