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,
     */
    
    
    
    //系统样式创建
    UITabBarItem *item1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:101];
    
    
    //通过 标题 图片 选中图片 --> 创建标签项
    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;
    
    /*———————————————————导航控制器———————————————————————————————————————————————————————————-*/
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:vc1];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:vc3];
    
    
    
    /**
     应用程序的基本层级关系:
     
     UIScreen -> UIWindow -> ROOTVC = TabBarController
                                        ↓
                                    ViewControllers = @[UINavigationController >=1]
                                                            ↓
                                                        rootViewController = UIViewController
                                                            ↓
                                (各种控件)subviews  <==    view
     
     */

    
    
    //创建  标签控制器
    UITabBarController *tbc = [[UITabBarController alloc]init];
    
    //设置 标签控制器管理的子控制器数组
    tbc.viewControllers = @[nav1,nav2,nav3];
    
    //将标签控制器管理的子控制器数组
    self.window.rootViewController = tbc;  
    
    return YES;
}


@end

Day.03.08 UITabBarController_第1张图片
屏幕快照 2016-03-08 上午10.15.10.png

你可能感兴趣的:(Day.03.08 UITabBarController)