#import "AppDelegate.h"app
#import "FirstViewController.h"字體
#import "SecondViewController.h"ui
#import "ThirdViewController.h"spa
#import "ForthViewController.h".net
#import "FifthViewController.h"3d
#import "SixthViewController.h"orm
#import "FJNavigationController.h"對象
@interface AppDelegate ()圖片
@end get
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[_window setBackgroundColor:[UIColor whiteColor]];
[_window makeKeyAndVisible];
[self createUI];
[self tabBarSetting];
[self tabBarItemSetting];
return YES;
}
#pragma mark - tabBarItem定製
- (void)tabBarItemSetting{
//兩種方式:
//1.直接設置視圖控制器的tabBarItem屬性:在建立須要標籤欄控制器管理的視圖控制器的時候去完成
//見createUI方法
//2.獲取tabBar上顯示的全部item而後設置對應的屬性:已經將須要標籤欄控制器
//管理的視圖控制器交給標籤欄控制器管理後去完成
//1.獲取全部的tabBarItem
UITabBarController *tabBarController =(UITabBarController *)_window.rootViewController;
NSArray *tabBarItems = tabBarController.tabBar.items;
//2.設置第三個item的屬性
UITabBarItem *item2 = tabBarItems[2];
[item2 setImage:[UIImage imageNamed:@"zhuanti_u"]];
[item2 setSelectedImage:[[UIImage imageNamed:@"zhuanti_d"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//3.
}
#pragma mark - 建立標籤欄控制器
- (void) createUI{
UITabBarController *tabBarcController = [[UITabBarController alloc]init];
//2.建立須要使用標籤欄控制器須要管理的視圖控制器對象
FirstViewController *first = [[FirstViewController alloc]init];
first.title = @"達令";
FJNavigationController *nav1 = [[FJNavigationController alloc]initWithRootViewController:first];
SecondViewController *second = [[SecondViewController alloc]init];
second.title = @"分類";
FJNavigationController *nav2 = [[FJNavigationController alloc]initWithRootViewController:second];
ThirdViewController *third = [[ThirdViewController alloc]init];
third.title = @"約惠";
FJNavigationController *nav3 = [[FJNavigationController alloc]initWithRootViewController:third];
ForthViewController *forth = [[ForthViewController alloc]init];
forth.title = @"達令幫";
FJNavigationController *nav4 = [[FJNavigationController alloc]initWithRootViewController:forth];
FifthViewController *fifth = [[FifthViewController alloc]init];
fifth.title = @"個人";
FJNavigationController *nav5 = [[FJNavigationController alloc]initWithRootViewController:fifth];
//===================定製tabBarItem=============
//界面1:
//1.設置標籤正常狀態下的圖片:若是選中圖片和沒有選中的圖片樣式是同樣的
//只是顏色不同,只須要設置tabBar的填充顏色就行,能夠不用設置選中狀態的圖片
[nav1.tabBarItem setImage:[UIImage imageNamed:@"faxian_u"]];
//2.設置選中狀態的圖片
[nav1.tabBarItem setSelectedImage:[[UIImage imageNamed:@"faxian_d"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
//3.設置標籤名
[nav1.tabBarItem setTitle:@"達令"];
//4.設置標籤字體和顏色(通常不用設置,只須要設置鏤空顏色就能夠!!);
// [nav1.tabBarItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],
// NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateSelected];
// [nav1.tabBarItem setTitleTextAttributes:@{NSFontAttributeName :[UIFont systemFontOfSize:15],NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
//5.同時設置全部的標籤的字體和顏色
//若是已經單獨設置過,那麼這個方法再去設置就無效
[ [UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15],NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
//界面2:
//1.設置正常狀態的圖片:
[nav2.tabBarItem setImage:[UIImage imageNamed:@"huiben_u"]];
//2.設置選中狀態的圖片
[nav2.tabBarItem setSelectedImage:[[UIImage imageNamed:@"huiben_d"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//3.設置標籤上的角標:
nav2.tabBarItem.badgeValue = @"77";
//4.設置角標消失
nav2.tabBarItem.badgeValue = nil;
tabBarcController.viewControllers = @[nav1,nav2,nav3,nav4,nav5];
tabBarcController.selectedIndex = 0;
_window.rootViewController = tabBarcController;
}
#pragma mark - 標籤欄控制器的定製--
//tabBa:屬於標籤欄控制器
//tabBarItem:屬於視圖控制器或者導航控制器(標籤控制器管理誰就屬於誰)
#pragma mark - 定製tabBar
//定製tabBar須要拿到標籤欄控制器
//(任何能夠拿到標籤欄控制器的tabBar)
- (void)tabBarSetting{
//1.拿到標籤欄控制器
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
//============定製tabBar=======================
//1.設置是否有透明度
[tabBarController.tabBar setTranslucent:NO];
//2.設置tabBar的顏色(至關於背景色)
[tabBarController.tabBar setBarTintColor:[UIColor purpleColor]];
//3.設置填充顏色(鏤空部分的顏色)
//至關於選中文字的顏色;
[tabBarController.tabBar setTintColor:[UIColor whiteColor]];
//4.設置背景圖片
// [tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:
// @"tabbg"] ];
}
@end