MainTabVC.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // MainTabVC.m
  3. // IBOSSMini
  4. //
  5. // Created by iHope on 14-6-5.
  6. // Copyright (c) 2014年 elongtian. All rights reserved.
  7. //
  8. #import "MainTabVC.h"
  9. #import "BusinessInfoViewController.h"
  10. @interface MainTabVC ()
  11. @end
  12. static MainTabVC *gHomeCtrl = nil;
  13. @implementation MainTabVC
  14. /**
  15. 初始化
  16. @param nibNameOrNil <#nibNameOrNil description#>
  17. @param nibBundleOrNil <#nibBundleOrNil description#>
  18. @return <#return value description#>
  19. */
  20. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  21. {
  22. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  23. if (self) {
  24. gHomeCtrl = self;
  25. }
  26. return self;
  27. }
  28. /**
  29. uicontroller
  30. @return <#return value description#>
  31. */
  32. + (UIViewController *)mRootCtrl {
  33. return gHomeCtrl;
  34. }
  35. /**
  36. viewDidLoad事件
  37. */
  38. - (void)viewDidLoad
  39. {
  40. [super viewDidLoad];
  41. // 业务处理
  42. self.businessvc=[[BusinessInfoViewController alloc] init];
  43. self.businessnavvc=[[BusinessNavVC alloc]initWithRootViewController:self.businessvc];
  44. self.businessnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  45. self.businessnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  46. UITabBarItem *messageItem= [[UITabBarItem alloc] initWithTitle: @"业务处理" image: nil tag: 0];
  47. messageItem.image= [UIImage imageNamed:@"icon_business@2x.png"];
  48. UIImage *businessPressedImg= [UIImage imageNamed:@"icon_business_pressed@2x.png"];
  49. businessPressedImg = [businessPressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  50. [messageItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  51. messageItem.selectedImage= businessPressedImg;
  52. self.businessnavvc.tabBarItem = messageItem;
  53. // 业务报表
  54. self.reportvc=[[ReportInfoViewController alloc] init];
  55. self.reportnavvc = [[ReportNavVC alloc] initWithRootViewController: self.reportvc];
  56. self.reportnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  57. self.reportnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  58. UITabBarItem *customerItem = [[UITabBarItem alloc] initWithTitle: @"业务报表" image: nil tag: 1];
  59. customerItem.image = [UIImage imageNamed:@"icon_report@2x.png"];
  60. UIImage *reportPressedImg= [UIImage imageNamed:@"icon_report_pressed@2x.png"];
  61. reportPressedImg = [reportPressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  62. [customerItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  63. customerItem.selectedImage=reportPressedImg;
  64. self.reportvc.tabBarItem = customerItem;
  65. // 我的
  66. self.settingvc=[[SettingViewController alloc] init];
  67. self.settingnavvc=[[SettingInfoNavVC alloc]initWithRootViewController:self.settingvc];
  68. self.settingnavvc.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:16]};
  69. self.settingnavvc.navigationBar.barTintColor = NavigationBarTintColor;
  70. UITabBarItem *moreinfoItem= [[UITabBarItem alloc] initWithTitle: @"我的" image: nil tag: 2];
  71. moreinfoItem.image=[UIImage imageNamed:@"icon_mine@2x.png"];
  72. UIImage *minePressedImg= [UIImage imageNamed:@"icon_mine_pressed@2x.png"];
  73. minePressedImg = [minePressedImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  74. [moreinfoItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.654 green:0 blue:0.027 alpha:1]} forState:UIControlStateSelected];
  75. moreinfoItem.selectedImage=minePressedImg;
  76. self.settingnavvc.tabBarItem = moreinfoItem;
  77. [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
  78. NSArray *array = [NSArray arrayWithObjects:self.businessnavvc,self.reportnavvc,self.settingnavvc,nil];
  79. self.viewControllers = array;
  80. self.selectedIndex = 0;
  81. }
  82. //!!!重点在viewWillAppear方法里调用下面两个方法
  83. -(void)viewWillAppear:(BOOL)animated{
  84. [self preferredStatusBarStyle];
  85. [self setStatusBarBackgroundColor:NavigationBarColor];
  86. }
  87. //设置状态栏颜色
  88. - (void)setStatusBarBackgroundColor:(UIColor *)color {
  89. self.selectedIndex = 2;
  90. if (@available(iOS 13.0, *)) {
  91. // iOS 13 弃用keyWindow属性 从所有windowl数组中取
  92. UIView *statusBar = [[UIView alloc]initWithFrame:[UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame] ;
  93. statusBar.backgroundColor = color;
  94. [[UIApplication sharedApplication].keyWindow addSubview:statusBar];
  95. } else{
  96. UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
  97. if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
  98. statusBar.backgroundColor = color;
  99. }
  100. }
  101. self.selectedIndex = 0;
  102. }
  103. - (void)setNeedsStatusBarAppearanceUpdate{
  104. [super setNeedsStatusBarAppearanceUpdate];
  105. }
  106. //设置状态栏的白色
  107. -(UIStatusBarStyle)preferredStatusBarStyle
  108. {
  109. return UIStatusBarStyleLightContent;
  110. }
  111. /**
  112. didReceiveMemoryWarning事件
  113. */
  114. - (void)didReceiveMemoryWarning
  115. {
  116. [super didReceiveMemoryWarning];
  117. }
  118. @end