您的位置:首页 > 产品设计 > UI/UE

2.UITabBar Navigation

2015-05-30 09:45 507 查看
//

//  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

97e5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UITabBar Navigation iOS