zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
//  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<NSAttributedStringKey, id> *selectedAttributes = [NSMutableDictionary dictionary];
    selectedAttributes[NSForegroundColorAttributeName] = PBColor(0, 122, 255);
    //tabBarItem title 未选中颜色
    NSMutableDictionary<NSAttributedStringKey, id> *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