多控制器的创建

//创建window

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


//初始化 tabbar controller

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


//创建子控制器

UIViewController * vc1 = [[UIViewController alloc] init];

UIViewController * vc2 = [[UIViewController alloc] init];

UIViewController * vc3 = [[UIViewController alloc] init];


//设置子控制器颜色

vc1.view.backgroundColor = [UIColor redColor];

vc2.view.backgroundColor = [UIColor blackColor];

vc3.view.backgroundColor = [UIColor orangeColor];


//添加自控制器到tabbartc

tc.viewControllers = @[vc1,vc2,vc3];


//设置tabbar内容

vc1.tabBarItem.title = @"论坛";

vc1.tabBarItem.image = [UIImage imageNamed:@"visitordiscover_image_message"];

vc2.tabBarItem.title = @"社区";

vc2.tabBarItem.image = [UIImage imageNamed:@"visitordiscover_image_profile"];

vc3.tabBarItem.title = @"设置";

vc3.tabBarItem.image = [UIImage imageNamed:@"tab_me_nor"];


//设置vindow的根控制器为tabbartc

self.window.rootViewController = tc;


//显示

[self.window makeKeyAndVisible];

return YES;

你可能感兴趣的:(OC)