UITabBarViewController(標簽視圖控制器) 用來管理沒有層級關系的視圖控制器
先來了解一下UITabBarViewController的創建
在Appdelegate.m文件中創建UITabBarViewController 首先一定要有多個視圖控制器 然后創建UITabBarViewController對視圖控制器進行管理
#import "AppDelegate.h"
#import "ViewController.h"
#import "FirstViewController.h"
#import "SecViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 創建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor whiteColor];
// 創建vc
ViewController *vc1 = [[ViewController alloc] init];
// 創建navigation
UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1];
FirstViewController *vc2 = [[FirstViewController alloc] init];
UINavigationController *navigation2 = [[UINavigationController alloc] initWithRootViewController:vc2];
SecViewController *vc3 = [[SecViewController alloc] init];
UINavigationController *navigation3 = [[UINavigationController alloc] initWithRootViewController:vc3];
// 創建UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// UITabBarController 有一個viewControllers屬性 在這個屬性里裝navigation
tabBarController.viewControllers = @[navigation1, navigation2, navigation3];
// 將tabBarController設置為根視圖控制器
self.window.rootViewController = tabBarController;
// 設置tabBar的標題 圖片中 實心圓表示的就是tabBar的標題:
navigation1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新聞" image:nil tag:100];
return YES;
}
// 如圖中空心圓箭頭所指就是
self.navigationItem.title = @"資訊";
DFC19D47-AA8A-4059-A77B-188505566593.png
// 設置tabBar的角標
navigation1.tabBarItem.badgeValue = @"10";
// 設置tabBar的顏色
tabBarController.tabBar.barTintColor = [UIColor cyanColor];
// 設置tabBar中元素的顏色
tabBarController.tabBar.tintColor = [UIColor blueColor];
忘了說tabBar的高度是49 而且tabBar數組中的元素一般不會大于5個