Day.03.08 UITabBarController

開頭不要忘了刪Main

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self.window makeKeyAndVisible];
    
    /*——————————————————————————————————————————————————————————————————————————————-*/
    
    UIViewController *vc1 = [[UIViewController alloc]init];
    
    vc1.view.backgroundColor = [UIColor redColor];
    
    vc1.title = @"第一頁";
    
    UIViewController *vc2 = [[UIViewController alloc]init];
    
    vc2.view.backgroundColor = [UIColor yellowColor];
    
    vc2.title = @"第二頁";
    
    UIViewController *vc3 = [[UIViewController alloc]init];
    
    vc3.view.backgroundColor = [UIColor blueColor];

    vc3.title = @"第三頁";
    
    
    
    /**
     UITabBarSystemItemMore,
     UITabBarSystemItemFavorites,
     UITabBarSystemItemFeatured,
     UITabBarSystemItemTopRated,
     UITabBarSystemItemRecents,
     UITabBarSystemItemContacts,
     UITabBarSystemItemHistory,
     UITabBarSystemItemBookmarks,
     UITabBarSystemItemSearch,
     UITabBarSystemItemDownloads,
     UITabBarSystemItemMostRecent,
     UITabBarSystemItemMostViewed,
     */
    
    
    
    //系統(tǒng)樣式創(chuàng)建
    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:101];
    
    
    //通過 標(biāo)題 圖片 選中圖片 --> 創(chuàng)建標(biāo)簽項
    UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"HOME" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_on"]];
    
    //
    UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"payticket" image:[UIImage imageNamed:@"payticket"] tag:103];
    
    
    vc1.tabBarItem = item1;
    vc2.tabBarItem = item2;
    vc3.tabBarItem = item3;
    
    /*———————————————————導(dǎo)航控制器———————————————————————————————————————————————————————————-*/
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    
    
    
    /**
     應(yīng)用程序的基本層級關(guān)系:
     
     UIScreen -> UIWindow -> ROOTVC = TabBarController
                                        ↓
                                    ViewControllers = @[UINavigationController >=1]
                                                            ↓
                                                        rootViewController = UIViewController
                                                            ↓
                                (各種控件)subviews  <==    view
     
     */

    
    
    //創(chuàng)建  標(biāo)簽控制器
    UITabBarController *tbc = [[UITabBarController alloc]init];
    
    //設(shè)置 標(biāo)簽控制器管理的子控制器數(shù)組
    tbc.viewControllers = @[nav1,nav2,nav3];
    
    //將標(biāo)簽控制器管理的子控制器數(shù)組
    self.window.rootViewController = tbc;  
    
    return YES;
}


@end

屏幕快照 2016-03-08 上午10.15.10.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容