1. 程式人生 > >TabBar——APP中下面的“導航” 介面跳轉

TabBar——APP中下面的“導航” 介面跳轉

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

self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

RedViewController *redVC = [RedViewControllernew];

UINavigationController *redNC = [[UINavigationControlleralloc

]initWithRootViewController:redVC];

OrangeViewController *orangeVC = [OrangeViewControllernew];

UINavigationController *orangeNC = [[UINavigationControlleralloc]initWithRootViewController:orangeVC];

YellowViewController *yellowVC = [YellowViewControllernew];

UINavigationController *yellowNC = [[

UINavigationControlleralloc]initWithRootViewController:yellowVC];

GreenViewController *greenVC = [GreenViewControllernew];

UINavigationController *greenNC = [[UINavigationControlleralloc]initWithRootViewController:greenVC];

CyanViewController *cyanVC = [CyanViewControllernew];

UINavigationController *cyanNC = [[

UINavigationControlleralloc]initWithRootViewController:cyanVC];

BlueViewController *blueVC = [BlueViewControllernew];

UINavigationController *blueNC = [[UINavigationControlleralloc]initWithRootViewController:blueVC];

PurpleViewController *purpleVC = [PurpleViewControllernew];

UINavigationController *purpleNC = [[UINavigationControlleralloc]initWithRootViewController:purpleVC];

#pragma mark tabBarController

//準備檢視控制器陣列

    NSArray *array = @[redNC,orangeNC,yellowNC,greenNC,cyanNC,blueNC,purpleNC];

//建立tabBarController

UITabBarController *tabBar = [[UITabBarControlleralloc]init];

//設定子檢視控制器

    tabBar.viewControllers = array;

//設定顏色,著色過程

    tabBar.tabBar.tintColor = [UIColormagentaColor];

//設定條的顏色

    tabBar.tabBar.barTintColor = [UIColorwhiteColor];

//大小,高度:49

//設定樣式

//    tabBar.tabBar.barStyle = UIBarStyleDefault;

//設定背景顏色

//    tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabBar"];

//跟事件相關的屬性

//預設選擇的是哪一個

    tabBar.selectedIndex = 3;

//設定badgeValue ---

    redVC.tabBarItem.badgeValue = @"HOT";

    orangeVC.tabBarItem.badgeValue = @"NEW";

//設定代理物件

    tabBar.delegate = self;

//一鍵換膚(同一修改UI--是一個單例

    [[UINavigationBarappearance] setBarTintColor:[UIColormagentaColor]];

//指定為根檢視控制器

    [self.windowsetRootViewController:tabBar];

self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

return YES;

}

#pragma mark  UITabBarControllerDelegate

//應用場景比較少

//將要選中控制器執行的方法

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

{

//請求資料在這弄完

return YES;

}

//已經選中控制器執行的方法

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

//請求頁面在這

    NSLog(@"");

}

=======================================

@implementation RedViewController

//M層資料寫在初始化方法,每一個item都是M

//初始化本身就是管理資料的。

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

        self.title = @"red";

//        self.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];

//        self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"chat" image:[UIImage imageNamed:@"08-chat"] selectedImage: [UIImage imageNamed:@"09-chat2"]];

//        //渲染

//        UIImage *image = [UIImage imageNamed:@"kiss.jpg"];

//        //渲染為原色版本

//        image= [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//        

//        self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"pp" image:image tag:101];

//        self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"clock" image:[UIImage imageNamed:@"11-clock"]  tag:100];

        UIImage *home = [UIImage imageNamed:@"iconfont-home"];

        self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首頁" image:home tag:101];

    }

return self;

}

//V層放在loadView中一種可以使用自己的view,一種就是使用自定義的view,需要一個指向。

- (void)viewDidLoad {

    [superviewDidLoad];

self.view.backgroundColor = [UIColorredColor];

}