美文网首页
TabBarController添加子控制器和统一设置导航栏

TabBarController添加子控制器和统一设置导航栏

作者: CoderZXS | 来源:发表于2019-02-18 15:45 被阅读0次
TabBarController添加子控制器
- (void)setupChildVC {
    
    NSArray *childItemsArray = @[
                                 @{ZXSClassKey:@"ZXSMessageController",
                                   ZXSTitleKey:@"微信",
                                   ZXSImageKey:@"tabbar_mainframe",
                                   ZXSSelectedImageKey:@"tabbar_mainframeHL"},
                                 
                                 @{ZXSClassKey:@"ZXSContactController",
                                   ZXSTitleKey:@"通讯录",
                                   ZXSImageKey:@"tabbar_contacts",
                                   ZXSSelectedImageKey:@"tabbar_contactsHL"},
                                 
                                 @{ZXSClassKey:@"ZXSDiscoverController",
                                   ZXSTitleKey:@"发现",
                                   ZXSImageKey:@"tabbar_discover",
                                   ZXSSelectedImageKey:@"tabbar_discoverHL"},
                                 
                                 @{ZXSClassKey:@"ZXSMeController",
                                   ZXSTitleKey:@"我",
                                   ZXSImageKey:@"tabbar_me",
                                   ZXSSelectedImageKey:@"tabbar_meHL"}
                                 ];
    
    [childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
        
        UIViewController *vc = [[NSClassFromString(dict[ZXSClassKey]) alloc] init];
        vc.title = dict[ZXSTitleKey];
        
        ZXSBaseNavigationController *nav = [[ZXSBaseNavigationController alloc] initWithRootViewController:vc];
        UITabBarItem *item = nav.tabBarItem;
        
        item.title = dict[ZXSTitleKey];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : ZXSTintColor} forState:UIControlStateSelected];
        item.image = [UIImage imageNamed:dict[ZXSImageKey]];
        item.selectedImage = [[UIImage imageNamed:dict[ZXSSelectedImageKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        
        [self addChildViewController:nav];
    }];
}
统一设置导航栏
+ (void)load {
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    navigationBar.barTintColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.9];
    navigationBar.tintColor = [UIColor whiteColor];
    navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}

相关文章

网友评论

      本文标题:TabBarController添加子控制器和统一设置导航栏

      本文链接:https://www.haomeiwen.com/subject/ctnaeqtx.html