你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> 淺談IOS UITabBarController

淺談IOS UITabBarController

編輯:IOS技巧綜合
[摘要]本文是對UITabBarController 初學的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

純代碼編寫UITabBarController, 不多說,直接見代碼

RViewController1 *vc1 = [[RViewController1 alloc]init];
    
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc1];
    //只賦值 tabBarItem.title, 通過.title屬性取值是取不到值
    //navController.tabBarItem.title = @"Page 1";
    
    //相當於對tabBarItem.title  和 navigationItem.title同時賦值
    navController.title = @"Page 1";
    navController.tabBarItem.image = [UIImage imageNamed:@"1.jpg"];
    
    RViewController2 *vc2 = [[RViewController2 alloc]init];
    vc2.title =@"Page 2";
//    UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"Page 2" image:[UIImage imageNamed:@"2.png" ] selectedImage:[UIImage imageNamed:@"2_pressed.png"]];
    vc2.tabBarItem.image = [UIImage imageNamed:@"2.png"];
    
    RViewController3 *vc3 = [[RViewController3 alloc]init];
    vc3.title =@"Page 3";
    vc3.tabBarItem.image = [UIImage imageNamed:@"3.png"];
    
    RViewController4 *vc4 = [[RViewController4 alloc]init];
    vc4.title =@"Page 4";
    vc4.tabBarItem.image = [UIImage imageNamed:@"4.png"];
    vc4.tabBarItem.badgeValue = @"10";
    
    RViewController5 *vc5 = [[RViewController5 alloc]init];
    
    //創建 UITabItem的實例
    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:0];
    vc5.tabBarItem = item1;
    
    NSArray *controllers = [NSArray arrayWithObjects:navController,vc2,vc3,vc4, nil];
    
    UITabBarController *tabController = [[UITabBarController alloc]init];
    tabController.viewControllers = controllers;
    
    self.window.rootViewController = tabController;
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved