The Fonz
The Fonz

Reputation: 207

How to add UITabBarController programatically without using AppDelegate?

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

Upvotes: 0

Views: 427

Answers (1)

Gajendra Rawat
Gajendra Rawat

Reputation: 3663

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];

Upvotes: 2

Related Questions