app标配控制器:UITabBarController

UITabBarController

UITabBarController和UINavigationController类似可以轻松的管理多个控制器,底部有一个条,底部条tabBar的高度是49.
UITabBarController内部结构:最外层是一个底部的tabBar,然后tabBar的下一层是一个存放子控制器的View,最内一层是UITabBarController的view.

初始化UITabBarController

1、 创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
2、 给窗口设置子控制器
UITabBarController *tabBar = [[UITabBarController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor redColor];
UIViewController *vc2 = [[UIViewController alloc] init];
[tabBar addChildViewController:vc1];
[tabBar addChildViewController:vc2];
self.window.rootViewController = tabBar;

3、显示窗口
[self.window makeKeyAndVisible];

添加子控制器到UITabBarController的方式

  • 调用addChildviewController方法
  • tabBar.viewControllers = @[vc1,vc2];
UITabBar

UITabBar内部有多少个UITabBarButton取决于UITabBarController内部有多少个子控制器,tabBar内部按钮均分,tabBar的高度是49;

UiTabBarButton

UITabBarButton里面显示什么内容,由对应子控制器的tabBarItem属性来决定。
vc1.tabBarItem.title = @"消息"
vc2.tabBarItem.image = [UIimage imageNamed:@""];

原文地址:https://www.cnblogs.com/xzk-it/p/5676828.html