view

    //1.创建标签控制器

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


    //2.创建相应的子控制器(viewcontroller)

    FirstViewController *firstVC = [FirstViewController new];

    firstVC.navigationItem.title = @"车票预订";

    firstVC.tabBarItem.title = @"车票预订";

    firstVC.tabBarItem.image = [UIImage imageNamed:@"[email protected]"];

    UINavigationController *firstNC = [[UINavigationController alloc]initWithRootViewController:firstVC];



    secondViewController *secondVC = [secondViewController new];

    secondVC.navigationItem.title = @"商旅服务";

    //设置标签名称

    secondVC.tabBarItem.title = @"商旅服务";

    //可以根据需求设置标签的的图标

    secondVC.tabBarItem.image = [UIImage imageNamed:@"[email protected]"];

    UINavigationController *secondNC = [[UINavigationController alloc]initWithRootViewController:secondVC];



    thirdViewController *thirdVC = [thirdViewController new];

    thirdVC.navigationItem.title = @"订单查询";

    thirdVC.tabBarItem.title = @"订单查询";

    thirdVC.tabBarItem.image = [UIImage imageNamed:@"[email protected]"];

    UINavigationController *thirdNC = [[UINavigationController alloc]initWithRootViewController:thirdVC];



    fourthViewController *fourthVC = [fourthViewController new];

    fourthVC.navigationItem.title = @"我的12306";

    fourthVC.tabBarItem.title = @"我的12306";

    fourthVC.tabBarItem.image = [UIImage imageNamed:@"[email protected]"];

    UINavigationController *fourthNC = [[UINavigationController alloc]initWithRootViewController:fourthVC];


    //3.添加到控制器


    NSArray *array = @[firstNC,secondNC,thirdNC,fourthNC];

    tab.viewControllers = array;


    tab.selectedIndex=0;

    [self.navigationController presentViewController:tab animated:YES completion:nil];





}

你可能感兴趣的:(view)