UITabBarController 筆記(一)AppDelegate中加UITabBarController 為 rootViewController

來源:互聯網
上載者:User

標籤:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    //初始化 tabBarItem對應的ViewController    UIViewController *viewCtrl1 = [[UIViewController alloc] init];    viewCtrl1.title = @"first viewctrl";    viewCtrl1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"rename first" image:nil tag:1];//自己定義tabBarItem是在對應的ViewController中去做    viewCtrl1.view.backgroundColor = [UIColor blueColor];        UIViewController *viewCtrl2 = [[UIViewController alloc] init];    viewCtrl2.title = @"second viewctrl";    viewCtrl2.view.backgroundColor = [UIColor yellowColor];    viewCtrl2.tabBarItem.badgeValue = @"360";        UIViewController *viewCtrl3 = [[UIViewController alloc] init];    viewCtrl3.title = @"3 viewctrl";    viewCtrl3.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:1.0];        UIViewController *viewCtrl4 = [[UIViewController alloc] init];    viewCtrl4.title = @"4 viewctrl";    viewCtrl4.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.3 alpha:1.0];        UIViewController *viewCtrl5 = [[UIViewController alloc] init];    viewCtrl5.title = @"5 viewctrl";    viewCtrl5.view.backgroundColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0];        UIViewController *viewCtrl6 = [[UIViewController alloc] init];    viewCtrl6.title = @"6 viewctrl";    viewCtrl6.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.5 blue:0.7 alpha:1.0];        UIViewController *viewCtrl7 = [[UIViewController alloc] init];    viewCtrl7.title = @"7 viewctrl";    viewCtrl7.view.backgroundColor = [UIColor colorWithRed:0.9 green:0.5 blue:0.3 alpha:1.0];        //    tabBarCtrl = [[UITabBarController alloc] init];    tabBarCtrl.viewControllers = [NSArray arrayWithObjects:viewCtrl1, viewCtrl2 ,viewCtrl5,  viewCtrl3, viewCtrl4, viewCtrl6, viewCtrl7, nil];//添加viewcontrollers, 數組順序就是tabBarItem對應的viewController順序 tabBarCtrl.customizableViewControllers = [NSArray arrayWithObjects: viewCtrl2 ,viewCtrl3, viewCtrl5, viewCtrl7, nil]; //顯示可編輯的有那些viewcontroller  [tabBarCtrl  setSelectedIndex: 3];//設定選中的是那個tabBarItem,如果為無效的index,則預設選中第一個tabBarCtrl.view.frame = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height); self.window.rootViewController = tabBarCtrl; [self.window makeKeyAndVisible]; return YES; } 關於旋轉UITabBarController預設只支援豎屏,當裝置方向放生變化時候,它會查詢viewControllers中包含的所有ViewController,僅當所有的viewController都支援該方向時,UITabBarController才會發生旋轉,否則預設的豎向。UITabBarController支援旋轉,而且發生旋轉的時候,只有當前顯示的viewController會接收到旋轉的訊息。 關於 UITabBarControllerDelegate 委託//設定使用者是否可以選中,如果返回NO,使用者不能選中,但代碼中還可以用tabBarCtrl  setSelectedIndex: 3]選中- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;{    return YES;}//選中後的訊息響應- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{} more 中edit監測- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers;- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;

 

UITabBarController 筆記(一)AppDelegate中加UITabBarController 為 rootViewController

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.