UITabBarViewController(標(biāo)簽視圖控制器) 用來(lái)管理沒有層級(jí)關(guān)系的視圖控制器
先來(lái)了解一下UITabBarViewController的創(chuàng)建
在Appdelegate.m文件中創(chuàng)建UITabBarViewController 首先一定要有多個(gè)視圖控制器 然后創(chuàng)建UITabBarViewController對(duì)視圖控制器進(jìn)行管理
#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.
// 創(chuàng)建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor whiteColor];
// 創(chuàng)建vc
ViewController *vc1 = [[ViewController alloc] init];
// 創(chuàng)建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];
// 創(chuàng)建UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// UITabBarController 有一個(gè)viewControllers屬性 在這個(gè)屬性里裝navigation
tabBarController.viewControllers = @[navigation1, navigation2, navigation3];
// 將tabBarController設(shè)置為根視圖控制器
self.window.rootViewController = tabBarController;
// 設(shè)置tabBar的標(biāo)題 圖片中 實(shí)心圓表示的就是tabBar的標(biāo)題:
navigation1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新聞" image:nil tag:100];
return YES;
}
// 如圖中空心圓箭頭所指就是
self.navigationItem.title = @"資訊";
DFC19D47-AA8A-4059-A77B-188505566593.png
// 設(shè)置tabBar的角標(biāo)
navigation1.tabBarItem.badgeValue = @"10";
// 設(shè)置tabBar的顏色
tabBarController.tabBar.barTintColor = [UIColor cyanColor];
// 設(shè)置tabBar中元素的顏色
tabBarController.tabBar.tintColor = [UIColor blueColor];
忘了說(shuō)tabBar的高度是49 而且tabBar數(shù)組中的元素一般不會(huì)大于5個(gè)