2.UITabBar Navigation

//

//  AppDelegate.h

//  Tab bar controllre

//

//  Created by 红珊瑚 on 15/5/21.

//  Copyright (c) 2015 红珊瑚. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

     

}


@property (strong, nonatomic) UIWindow *window;



@end




//

//  AppDelegate.m

//  Tab bar controllre

//

//  Created by 红珊瑚 on 15/5/21.

//  Copyright (c) 2015 红珊瑚. All rights reserved.

//


#import "AppDelegate.h"

#import "ViewController.h"

#import "ViewController2.h"

#import "ViewController3.h"

#import "ViewController4.h"


@interface AppDelegate ()


@end



@implementation AppDelegate



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

{

    //创建Window

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];


    //1.创建并初始化tabBar控制器

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

      //设置控制器为Window的根控制器

    self.window.rootViewController = tabBarView;

    

    //2.初始化4个子视图控制器

    ViewController *ViewCon1 = [[ViewController alloc] init];

    ViewController2 *ViewCon2 = [[ViewController2 alloc] init];

    ViewController3 *ViewCon3 = [[ViewController3 alloc] init];

    ViewController4 *ViewCon4 = [[ViewController4 alloc] init];

    

    //3.用导航试图控制器 管理4个子视图控制器

    UINavigationController *NavigaCon1 = [[UINavigationController alloc] initWithRootViewController:ViewCon1];

    UINavigationController *NavigaCon2 = [[UINavigationController alloc] initWithRootViewController:ViewCon2];

    UINavigationController *NavigaCon3 = [[UINavigationController alloc] initWithRootViewController:ViewCon3];

    UINavigationController *NavigaCon4 = [[UINavigationController alloc] initWithRootViewController:ViewCon4];

      //为每一个导航控制器的title属性设置标题

    NavigaCon1.title = @"首页";

    NavigaCon2.title = @"名人";

    NavigaCon3.title = @"名车";

    NavigaCon4.title = @"我的";

      //为每一个导航控制器的tabBarItem.image属性设置图标

    NavigaCon1.tabBarItem.image = [UIImage imageNamed:@"check.png"];

    NavigaCon2.tabBarItem.image = [UIImage imageNamed:@"check.png"];

    NavigaCon3.tabBarItem.image = [UIImage imageNamed:@"check.png"];

    NavigaCon4.tabBarItem.image = [UIImage imageNamed:@"check.png"];

    

    //4.改变UITabBarItem的字的位置

    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -3.0)];


    //5.创建一个数据包含4个导航控制器

    NSArray *Controllers = [NSArray arrayWithObjects:NavigaCon1,NavigaCon2,NavigaCon3,NavigaCon4, nil];

     //将数据传给UITabBarViewController

    tabBarView.viewControllers = Controllers;

    

    //设置Window为主窗口并显示出来

    [self.window  makeKeyAndVisible];

        return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值