UITabBarController
標簽視圖控制器
?標簽視圖控制器
UITabBar
標簽,包含多個UITabBarItem,每一個UITabBarItem對應一個UIViewController,UITabBar的高度是49。系統(tǒng)最多只顯示5個UITabBarItem,當UITabBarItem超過5個時系統(tǒng)會自動添加一個更多按鈕。
UIAppearance
如果想通過一件設定所有導航視圖控制器的顏色,類似于QQ的一鍵換膚操作,可以通過UIAppearance協(xié)議來進行操作。
FirstViewController *fisrtVC = [[FirstViewController alloc] init];
UINavigationController *firstNaVC = [[UINavigationController alloc] initWithRootViewController:fisrtVC];
firstNaVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:101];
firstNaVC.tabBarItem.badgeValue = @"10";
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNaVC = [[UINavigationController alloc] initWithRootViewController:secondVC];
secondNaVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:102];
secondNaVC.tabBarItem.badgeValue = @"未讀";
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNaVC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNaVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:103];
thirdNaVC.tabBarItem.badgeValue = @"警告";
// 1.創(chuàng)建UITabBarController
UITabBarController *tabBarVC = [[UITabBarController alloc] init];
// 2.將tabBarVC管理的視圖控制器放到一個數(shù)組中
NSArray *VCs = [NSArray arrayWithObjects:firstNaVC, secondNaVC, thirdNaVC, nil];
// 3.設置tabBarVC的子視圖控制器
tabBarVC.viewControllers = VCs;
self.window.rootViewController = tabBarVC;
// 設置tabBarVC的屬性
tabBarVC.tabBar.tintColor = [UIColor redColor];// 設置選中顏色
tabBarVC.tabBar.backgroundColor = [UIColor lightGrayColor];// 設置背景顏色
tabBarVC.tabBar.translucent = YES;// 是否半透明,默認為YES
// 設置全局外觀,設置全局外觀最好在appDelegate里,否則會無效
[[UITabBar appearance] setBarTintColor:[UIColor cyanColor]];// 設置UITabBar背景顏色
[[UITabBar appearance] setTintColor:[UIColor brownColor]];// 設置UITabBar樣式
[[UINavigationBar appearance] setBarTintColor:[UIColor lightGrayColor]];// 設置UINavigationBar外觀顏色
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:17], NSFontAttributeName, nil]];// 設置UINavigationBar字體屬性
- UITabBarController、UINavigationController、UITableViewController通常都是組合出現(xiàn),這種布局方式特別常見。
- UITabBarController可以嵌套UINavigationController。
- UITabBarController也可以模態(tài)UINavigationController。