UITabBarController动态添加TabBarItem

Posted Gerry_hu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UITabBarController动态添加TabBarItem相关的知识,希望对你有一定的参考价值。

   NSArray *titles = @[L(@"首页"), L(@"新闻"), L(@"消息"), L(@"我的")];
    
    NSArray *images = @[@"bottom_tabbar_home", @"bottom_tabbar_news", @"bottom_tabbar_message", @"bottom_tabbar_my"];
    
    NSArray *imagesSel = @[@"bottom_tabbar_home_selected", @"bottom_tabbar_news_selected", @"bottom_tabbar_message_selected", @"bottom_tabbar_my_selected"];
    
    NSMutableArray * tabarr = [NSMutableArray new];
    
    [tabarr addObject:[self createChildrenCtrWithtitle:titles[0]]];

    [tabarr addObject:[self createChildrenCtrWithtitle:titles[1]]];
    
    [tabarr addObject:[self createChildrenCtrWithtitle:titles[2]]];

    [tabarr addObject:[self createChildrenCtrWithtitle:titles[3]]];
    
    self.viewControllers = tabarr;
    
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
        item.title = titles[idx];
        UIImage *img = [UIImage imageNamed:images[idx]];
        UIImage *selectImg = [UIImage imageNamed:imagesSel[idx]];
        item.image =  [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [selectImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }];

 

以上是关于UITabBarController动态添加TabBarItem的主要内容,如果未能解决你的问题,请参考以下文章

jquery 动态添加tab 效果

以编程方式在 UITabBarController 和 UINavigationController 中呈现视图

ASP.NET中后台不能动态添加前台tab页面

有没有Bootstrap3.3 动态添加和关闭 tab的方案

Objective-C:具有拆分视图的 UITabBarController

QML TabView动态添加tab和赋初值