123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // JYTabBarController.m
- // D2-CustomTabBarController
- //
- // Created by Jerry on 15/12/15.
- // Copyright © 2015年 Jerry. All rights reserved.
- //
- #import "TabBarController.h"
- #import "MyUINavigationController.h"
- //主页
- #import "HomeBaseVC.h"
- #import "LearnDrivingVC.h"
- #import "SearchBase.h"
- #import "FunctionVC.h"
- //#import "TimingBaseVC.h"
- #import "NeighbouringVC.h"
- @interface TabBarController ()
- {
- HomeBaseVC * _hbVC;//为了在hbVC里可以控制sidevc进行跳转
- }
- @end
- @implementation TabBarController
- - (instancetype)init
- {
- if (self = [super init]) {
- self.tabBar.backgroundColor = backGroundColor;
- //创建管理的子视图控制器
- [self createViewControllers];
- }
- return self;
- }
- - (void)createViewControllers
- {
- //创建要管理的子视图控制器
- NSArray *titles = @[@[@"考试",@"tabbarImg1"],
- @[@"社区",@"tabbarImg2"],
- // @[@"计时",@"tabbarImg5"],
- @[@"报名点",@"tabbarImg3"],
- @[@"个人",@"tabbarImg4"]];
- NSArray *vcName = @[@"HomeBaseVC",@"LearnDrivingVC",@"NeighbouringVC",@"FunctionVC"];//,@"TimingBaseVC"
- NSMutableArray *controllers = [NSMutableArray array];
- for (NSInteger i=0; i<titles.count; i++) {
-
- Class cls = NSClassFromString(vcName[i]);
- UIViewController *bvc = [[cls alloc] init];
- if ([vcName[i] isEqualToString:@"SearchBase"]) {
- SearchBase * sbVC = (SearchBase*)bvc;
- sbVC.type = 2;
- }
- if ([vcName[i] isEqualToString:@"HomeBaseVC"]) {
- _hbVC = (HomeBaseVC*)bvc;
- }
- MyUINavigationController * naVC = [[MyUINavigationController alloc]initWithRootViewController:bvc];
-
- //创建item
- //正常状态图片
- UIImage *image = [[[UIImage imageNamed:titles[i][1]] tint:[UIColor grayColor] ] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- //选中状态图片
- UIImage *selectedImage = [[[UIImage imageNamed:titles[i][1]] tint:defGreen ] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:titles[i][0] image:image selectedImage:selectedImage];
- bvc.tabBarItem = item;
-
- //保存到数组中
- [controllers addObject:naVC];
- }
- //统一设置tabBarItem的标题属性
- [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:subTitleColor,NSFontAttributeName:[UIFont scaleSize:13]} forState:UIControlStateNormal];
- [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:defGreen,NSFontAttributeName:[UIFont scaleSize:13]} forState:UIControlStateSelected];
-
-
- //设置所管理的视图控制器
- self.viewControllers = controllers;
- }
- -(void)setSideVC:(YRSideViewController *)sideVC{
- _sideVC = sideVC;
- _hbVC.sideVC = sideVC;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.tabBar.tintColor = [UIColor whiteColor];
- self.tabBar.barTintColor = [UIColor whiteColor];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|