TabBarController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // JYTabBarController.m
  3. // D2-CustomTabBarController
  4. //
  5. // Created by Jerry on 15/12/15.
  6. // Copyright © 2015年 Jerry. All rights reserved.
  7. //
  8. #import "TabBarController.h"
  9. #import "MyUINavigationController.h"
  10. //主页
  11. #import "HomeBaseVC.h"
  12. #import "LearnDrivingVC.h"
  13. #import "SearchBase.h"
  14. #import "FunctionVC.h"
  15. //#import "TimingBaseVC.h"
  16. #import "NeighbouringVC.h"
  17. @interface TabBarController ()
  18. {
  19. HomeBaseVC * _hbVC;//为了在hbVC里可以控制sidevc进行跳转
  20. }
  21. @end
  22. @implementation TabBarController
  23. - (instancetype)init
  24. {
  25. if (self = [super init]) {
  26. self.tabBar.backgroundColor = backGroundColor;
  27. //创建管理的子视图控制器
  28. [self createViewControllers];
  29. }
  30. return self;
  31. }
  32. - (void)createViewControllers
  33. {
  34. //创建要管理的子视图控制器
  35. NSArray *titles = @[@[@"考试",@"tabbarImg1"],
  36. @[@"社区",@"tabbarImg2"],
  37. // @[@"计时",@"tabbarImg5"],
  38. @[@"报名点",@"tabbarImg3"],
  39. @[@"个人",@"tabbarImg4"]];
  40. NSArray *vcName = @[@"HomeBaseVC",@"LearnDrivingVC",@"NeighbouringVC",@"FunctionVC"];//,@"TimingBaseVC"
  41. NSMutableArray *controllers = [NSMutableArray array];
  42. for (NSInteger i=0; i<titles.count; i++) {
  43. Class cls = NSClassFromString(vcName[i]);
  44. UIViewController *bvc = [[cls alloc] init];
  45. if ([vcName[i] isEqualToString:@"SearchBase"]) {
  46. SearchBase * sbVC = (SearchBase*)bvc;
  47. sbVC.type = 2;
  48. }
  49. if ([vcName[i] isEqualToString:@"HomeBaseVC"]) {
  50. _hbVC = (HomeBaseVC*)bvc;
  51. }
  52. MyUINavigationController * naVC = [[MyUINavigationController alloc]initWithRootViewController:bvc];
  53. //创建item
  54. //正常状态图片
  55. UIImage *image = [[[UIImage imageNamed:titles[i][1]] tint:[UIColor grayColor] ] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  56. //选中状态图片
  57. UIImage *selectedImage = [[[UIImage imageNamed:titles[i][1]] tint:defGreen ] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  58. UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:titles[i][0] image:image selectedImage:selectedImage];
  59. bvc.tabBarItem = item;
  60. //保存到数组中
  61. [controllers addObject:naVC];
  62. }
  63. //统一设置tabBarItem的标题属性
  64. [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:subTitleColor,NSFontAttributeName:[UIFont scaleSize:13]} forState:UIControlStateNormal];
  65. [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:defGreen,NSFontAttributeName:[UIFont scaleSize:13]} forState:UIControlStateSelected];
  66. //设置所管理的视图控制器
  67. self.viewControllers = controllers;
  68. }
  69. -(void)setSideVC:(YRSideViewController *)sideVC{
  70. _sideVC = sideVC;
  71. _hbVC.sideVC = sideVC;
  72. }
  73. - (void)viewDidLoad {
  74. [super viewDidLoad];
  75. // Do any additional setup after loading the view.
  76. self.tabBar.tintColor = [UIColor whiteColor];
  77. self.tabBar.barTintColor = [UIColor whiteColor];
  78. }
  79. - (void)didReceiveMemoryWarning {
  80. [super didReceiveMemoryWarning];
  81. // Dispose of any resources that can be recreated.
  82. }
  83. /*
  84. #pragma mark - Navigation
  85. // In a storyboard-based application, you will often want to do a little preparation before navigation
  86. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  87. // Get the new view controller using [segue destinationViewController].
  88. // Pass the selected object to the new view controller.
  89. }
  90. */
  91. @end