如何在不使用 AppDelegate 的情况下以编程方式添加 UITabBarController? [英] How to add UITabBarController programatically without using AppDelegate?

查看:28
本文介绍了如何在不使用 AppDelegate 的情况下以编程方式添加 UITabBarController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个视图中放置一个 UITabBar,而不是在 MainViewController 中,因为我没有使用 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.

是否有没有 .xib 或 storyboard 的解决方案

Is there a solution without .xib or storyboard

推荐答案

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

这篇关于如何在不使用 AppDelegate 的情况下以编程方式添加 UITabBarController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆