APPDelegate

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

    // Override point for customization after application launch.

    //创建窗口    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    //只要创建对象类型,就用*

    //mainScreen 是类方法

    //UIScreen是获取设备屏幕的信息的

    UIScreen* mainScreen=[UIScreenmainScreen];

    //设置应用的屏幕大小

    self.window= [[UIWindowalloc]initWithFrame:[mainScreenbounds]];

    //设置应用窗口的颜色

    self.window.backgroundColor = [UIColor whiteColor];

    //告诉应用windows是应用的主窗口

    [self.window makeKeyAndVisible];


    //创建具有容器功能的控制器

    //展示内容的控制器(导航容器)

    HomePageViewController * hpvc = [[HomePageViewController alloc] init];

    hpvc.view.backgroundColor = [UIColor yellowColor];

    UINavigationController * navigationHPVC = [[UINavigationController alloc] initWithRootViewController:hpvc];

    //

    CourseViewController * cvc = [[CourseViewController alloc] init];

    cvc.view.backgroundColor = [UIColor purpleColor];

    UINavigationController * navigationCVC = [[UINavigationController alloc] initWithRootViewController:cvc];


    ScheduleViewController * svc=[[ScheduleViewController alloc] init];

    svc.view.backgroundColor = [UIColor orangeColor];

    UINavigationController *navigationSVC = [[UINavigationController alloc] initWithRootViewController:svc];


    PersonalViewController * pvc = [[PersonalViewController alloc] init];

    pvc.view.backgroundColor = [UIColor blueColor];

    UINavigationController * navigationPVC = [[UINavigationController alloc] initWithRootViewController:pvc];



    //创建容器

    UITabBarController * tabBarController = [[UITabBarController alloc]init];

    NSArray* controllers =@[navigationCVC,navigationPVC,navigationSVC,navigationHPVC];


    tabBarController.viewControllers= controllers;

    self.window.rootViewController= tabBarController;

    NSArray * imgs = @[@"nav01",@"nav02",@"nav03",@"nav04"];

    NSArray * sImgs = @[@"nav01on",@"nav02on",@"nav03on",@"nav04on"];

    for(inti =0; i

        UINavigationController* navic = controllers[i];

        //初始化图片,并设置图片的渲染模式为原始图片设置

        UIImage * image = [[UIImage imageNamed:imgs[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        UIImage* selectImage = [[UIImageimageNamed:sImgs[i]]

    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

        //tabbar 的默认样式,是上面图片,下面是标题,为了让图片能居中显示,一下做了图片偏移

        UITabBarItem* tabbar =[[UITabBarItemalloc]initWithTitle:@""image:imageselectedImage:selectImage];

        //设置图片的偏移

        [tabbarsetImageInsets:UIEdgeInsetsMake(7, 0, -7, 0)];

        navic.tabBarItem= tabbar;


    }

    //创建容器(选项卡容器每一个选项卡都内置了一个导航容器,)

    UITabBarController * tabbarController = [[UITabBarController alloc] init];

    tabbarController.viewControllers=@[navigationHPVC,navigationCVC,navigationSVC,navigationPVC];

    //展示在窗口上,给UIwindow设置根处理器

    self.window.rootViewController= tabbarController;


    //一共两个容器:选项卡容器、导航容器(作用:内容和内容之间的切换)

    return YES;

}

你可能感兴趣的:(APPDelegate)