How to add UITabBarController programatically without using AppDelegate?

别等时光非礼了梦想. 提交于 2020-01-06 12:42:55

问题


I want to put a UITabBar in two views, but not in the MainViewController, because I am not using the AppDelegate to put it.

Is there a solution without .xib or storyboard


回答1:


UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = @"FIRST";
vc1.view.backgroundColor = [UIColor blueColor];

UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"SECOND";
vc2.view.backgroundColor = [UIColor redColor];

UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = @[vc1,vc2];
tabBar.selectedIndex   = 1;
tabBar.view.frame = CGRectMake(50, 50, 220, 320);

[tabBar willMoveToParentViewController:self];
[self.view addSubview:tabBar.view];
[self addChildViewController:tabBar];
[tabBar didMoveToParentViewController:self];


来源:https://stackoverflow.com/questions/22195806/how-to-add-uitabbarcontroller-programatically-without-using-appdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!