动态显示、影藏其中某个tabBarItem

2019-10-09  本文已影响0人  KobeBrant

关键代码

显示

//显示
    TabBarController *tabBarController = (TabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
    ViewController2 * threeVc = [ViewController2 new];
    threeVc.title = @"三";
    threeVc.tabBarItem.image = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    threeVc.tabBarItem.selectedImage = [[UIImage imageNamed:@""] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 为子控制器包装导航控制器
    UINavigationController * navigationVc = [[UINavigationController alloc] initWithRootViewController:threeVc];
    [tabbarViewControllers insertObject:navigationVc atIndex:2];
    [tabBarController setViewControllers: tabbarViewControllers];

影藏

//隐藏
    TabBarController *tabBarController = (TabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
    [tabbarViewControllers removeObjectAtIndex:2];
    [tabBarController setViewControllers: tabbarViewControllers];
上一篇下一篇

猜你喜欢

热点阅读