// // NewBasicTabbarController.m // MingMen // // Created by 罗云飞 on 2017/3/9. // Copyright © 2017年 罗云飞. All rights reserved. // #import "NewBasicTabbarController.h" #import "HomeRootVC.h"//首页 #import "TechnologyVC.h"//技术 #import "ConversationVC.h"//交谈 #import "MineVC.h"//我的 #import "AmoytechniqueViewController.h"//淘技 #import "FXViewController.h"//发现 #import "ZCJDViewController.h" #import "NewMineViewController.h" #import "GUWENViewController.h"//顾问 #import "JitaoHomeViewController.h"//技淘首页 #import "NewFXViewController.h" #import "NewMyViewController.h" @interface NewBasicTabbarController () @end static NewBasicTabbarController *sharedObj = nil; static dispatch_once_t onceToken; @implementation NewBasicTabbarController + (NewBasicTabbarController *) sharedInstance { //static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^{ sharedObj = [[super allocWithZone: NULL] init]; }); return sharedObj; } + (id) allocWithZone:(struct _NSZone *)zone { return [self sharedInstance]; } - (id) copyWithZone:(NSZone *) zone { return self; } +(void)objectDealloc{ // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象. // 应用场景:切换账号、从新登陆 onceToken = 0; sharedObj = nil; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self loadsView]; self.tabBar.barTintColor = [UIColor whiteColor]; //self.tabBar.translucent = YES;//设置不透明背景 /* //更改tabBar顶部线条颜色 CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 1); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, NewNavigationColor.CGColor); CGContextFillRect(context, rect); UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self.tabBar setShadowImage:img]; [self.tabBar setBackgroundImage:[[UIImage alloc]init]]; */ } // 初始化所有子控制器 - (void)loadsView{ [self setTabBarChildController:[[JitaoHomeViewController alloc] init] title:@"技淘" image:@"jt-min" selectImage:@"jtxz-min"]; [self setTabBarChildController:[[GUWENViewController alloc] init] title:@"顾问" image:@"gw-min" selectImage:@"gwxz-min"]; [self setTabBarChildController:[[NewFXViewController alloc] init] title:@"发现" image:@"fx-min" selectImage:@"fxxz-min"]; [self setTabBarChildController:[[NewMyViewController alloc] init] title:@"我的" image:@"wd-min" selectImage:@"wdxz-min"]; } // 添加tabbar的子viewcontroller - (void)setTabBarChildController:(UIViewController*)controller title:(NSString*)title image:(NSString*)imageStr selectImage:(NSString*)selectImageStr{ UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller]; nav.tabBarItem.title = title; // if ([title isEqualToString:@"FM"]) { // nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -10); // } nav.tabBarItem.image = [[UIImage imageNamed:imageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithString:@"#3C3C3C"]} forState:UIControlStateNormal];//NewRGBColor(74, 74, 74, 1.0) [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:NewButtonColor} forState:UIControlStateSelected];//NewRGBColor(255, 150, 38, 1.0) [self addChildViewController:nav]; } - (void)changeRootViewControllerEvent:(NSInteger)changeIndex{ [self setSelectedIndex:changeIndex]; //__weak typeof(self) wself = self; //[wself setSelectedIndex:changeIndex]; } - (void)dealloc { NSLog(@"Tabbar单例类销毁"); } - (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