MyTabbarController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // MyTabbarController.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/6.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "MyTabbarController.h"
  9. #import "MyUINavigationController.h"
  10. #import "WillDoVC.h"
  11. #import "JobVC.h"
  12. #import "WaringVC.h"
  13. //#import "statisticsVC.h"
  14. #import "MeCenterVC.h"
  15. @interface MyTabbarController ()
  16. @end
  17. @implementation MyTabbarController
  18. - (void)addControllers
  19. {
  20. //创建要管理的子视图控制器
  21. NSArray *titles = @[@[@"消息",@"tabbar_1",@"tabbar_1_H"],
  22. @[@"功能",@"tabbar_2",@"tabbar_2_H"],
  23. @[@"预警",@"tabbar_3",@"tabbar_3_H"],
  24. @[@"个人",@"tabbar_4",@"tabbar_4_H"]];
  25. NSArray *vcName = @[@"WillDoVC",@"JobVC",@"WaringVC",@"MeCenterVC"];
  26. NSMutableArray *controllers = [NSMutableArray array];
  27. for (NSInteger i=0; i<titles.count; i++) {
  28. Class cls = NSClassFromString(vcName[i]);
  29. UIViewController *bvc = [[cls alloc] init];
  30. MyUINavigationController * naVC = [[MyUINavigationController alloc]initWithRootViewController:bvc];
  31. //创建item
  32. //正常状态图片
  33. UIImage *image = [[UIImage imageNamed:titles[i][1]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  34. //选中状态图片
  35. UIImage *selectedImage = [[[UIImage imageNamed:titles[i][1]] tint:COLOR_THEME] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  36. UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:titles[i][0] image:image selectedImage:selectedImage];
  37. bvc.tabBarItem = item;
  38. //保存到数组中
  39. [controllers addObject:naVC];
  40. }
  41. //统一设置tabBarItem的标题属性
  42. // UIColor *color = [UIColor colorWithRed:39/255.0 green:38/255.0 blue:54/255.0 alpha:1.0];
  43. [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_THEME} forState:UIControlStateSelected];
  44. //设置所管理的视图控制器
  45. self.viewControllers = controllers;
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. self.tabBar.backgroundColor = [UIColor colorWithRed:222 / 250.0 green:222 / 250.0 blue:222 / 250.0 alpha:1.0];
  50. [self addControllers];
  51. }
  52. - (void)didReceiveMemoryWarning {
  53. [super didReceiveMemoryWarning];
  54. // Dispose of any resources that can be recreated.
  55. }
  56. /*
  57. #pragma mark - Navigation
  58. // In a storyboard-based application, you will often want to do a little preparation before navigation
  59. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  60. // Get the new view controller using [segue destinationViewController].
  61. // Pass the selected object to the new view controller.
  62. }
  63. */
  64. @end