// // NewBasicTabbarController.m // MingMen // // Created by 罗云飞 on 2017/3/9. // Copyright © 2017年 罗云飞. All rights reserved. // #import "NewBasicTabbarController.h" #import "HomeRootVC.h" #import "PersonalRootVC.h" #import "DateRootVC.h" #import "FindRootVC.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:[[HomeRootVC alloc] init] title:@"首页" image:@"菜单栏-首页" selectImage:@"菜单栏-首页press"]; [self setTabBarChildController:[[DateRootVC alloc] init] title:@"约会" image:@"菜单栏-约会" selectImage:@"菜单栏-约会press"]; [self setTabBarChildController:[[FindRootVC alloc] init] title:@"发现" image:@"菜单栏-发现" selectImage:@"菜单栏-发现press"]; [self setTabBarChildController:[[PersonalRootVC alloc] init] title:@"个人" image:@"菜单栏-个人" selectImage:@"菜单栏-个人press"]; } // 添加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:NewGray2Color} forState:UIControlStateNormal];//NewRGBColor(74, 74, 74, 1.0) [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:NewNavigationColor} 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