// // PBTabBarController.m // IphoneBIMe // // Created by zjf on 2018/7/18. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBTabBarController.h" #import "PBNavigationController.h" #import "PBProjectModel.h" #import "PBProjectPower.h" #import "AppDelegate.h" @interface PBTabBarController () @property (nonatomic, strong) NSArray *powerArr; @end @implementation PBTabBarController - (void)viewDidLoad { [super viewDidLoad]; if(@available(iOS 13.0,*)){ UITabBarAppearance*appearance=[[UITabBarAppearance alloc]init]; // 背景色 appearance.backgroundColor=[UIColor whiteColor]; self.tabBar.standardAppearance=appearance; if(@available(iOS 15.0,*)){ //tabBaritem title选中状态颜色 appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName:PBColor(0, 122, 255)}; //tabBaritem title未选中状态颜色 appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName:PBColor(40, 58, 79)}; self.tabBar.scrollEdgeAppearance=appearance; }} self.view.backgroundColor = [UIColor whiteColor]; [PBNoteCenter addObserver:self selector:@selector(dismissTabBarController:) name:PBNoteCenterDismissTabBarController object:nil]; [self setTabBarColorStyle]; } - (void)setTabBarColorStyle { //tabBarItem title 选中颜色 NSMutableDictionary *selectedAttributes = [NSMutableDictionary dictionary]; selectedAttributes[NSForegroundColorAttributeName] = PBColor(0, 122, 255); //tabBarItem title 未选中颜色 NSMutableDictionary *normalAttributes = [NSMutableDictionary dictionary]; normalAttributes[NSForegroundColorAttributeName] = PBColor(40, 58, 79); if (@available(iOS 13.0, *)) { UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init]; tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes.copy; tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes.copy; self.tabBar.standardAppearance = tabBarAppearance; } else { //设置 tabBarItem title 颜色 for (UIViewController *vc in self.viewControllers) { [vc.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateNormal]; [vc.tabBarItem setTitleTextAttributes:selectedAttributes.copy forState:UIControlStateSelected]; } } } #pragma mark - 添加子控制器的代码 - (void)setupChildVcs { UIViewController *bussinessController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBBussinessViewController" title:@"业务" imageName:@"TabBar_bussiness"]]; UIViewController *modelController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBModelViewController" title:@"模型" imageName:@"TabBar_model"]]; UIViewController *docController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBDocListController" title:@"文档" imageName:@"TabBar_Doc"]]; UIViewController *issueController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBIssueListViewController" title:@"协作" imageName:@"TabBar_Issue"]]; UIViewController *examineController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBExamineListViewController" title:@"现场" imageName:@"TabBar_bussiness"]]; UIViewController *scheduleController = [[PBNavigationController alloc] initWithRootViewController:[self controllerWith:@"PBScheduleListViewController" title:@"进度" imageName:@"TabBar_Doc"]]; self.viewControllers = @[bussinessController, issueController, modelController, docController]; } - (UIViewController *)controllerWith:(NSString *)className title:(NSString *)title imageName:(NSString *)imageName{ Class clz = NSClassFromString(className); UIViewController *controller = [[clz alloc]init]; NSAssert([controller isKindOfClass:[UIViewController class]], @"%@ 写错了, 没有这个类", className); controller.title = _projectModel.fullname; return [self controller:controller WithTitle:title imageName:imageName]; } - (UIViewController *)controller:(UIViewController *)controller WithTitle:(NSString *)title imageName:(NSString *)imageName{ controller.tabBarItem.title = title; controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_select",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [controller setValue:_projectModel forKey:@"projectModel"]; [controller setValue:self.powerArr forKey:@"powerArr"]; return controller; } - (void)dismissTabBarController:(NSNotification *)noti { [self dismissViewControllerAnimated:YES completion:nil]; } - (void)dealloc{ [PBNoteCenter removeObserver:self]; } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; [self loadAccount]; // [self setupChildVcs]; } - (void)loadAccount { // [YJProgressHUD showCustomAnimation:@"" inview:self.view]; [YJProgressHUD showProgress:@"" inView:self.view]; [[PBNetworkTools sharedTools] GetUserOrgFuncAuthWithOrganizeID:_projectModel.organizeid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { [YJProgressHUD hide]; if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"加载失败" inView:self.view]; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self dismissViewControllerAnimated:YES completion:nil]; }); return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1) { NSMutableArray *arrM = [[NSMutableArray alloc] init]; for (NSDictionary *obj in networkModel.Data) { PBProjectPower *power = [PBProjectPower yy_modelWithDictionary:obj]; [arrM addObject:power]; } self.powerArr = arrM.copy; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; appDelegate.powerArr = self.powerArr; [self setupChildVcs]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self dismissViewControllerAnimated:YES completion:nil]; }); } }]; } - (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