码迷,mamicode.com
首页 > 其他好文 > 详细

UITabBarController动态添加TabBarItem

时间:2017-05-24 15:57:28      阅读:885      评论:0      收藏:0      [点我收藏+]

标签:nbsp   nal   select   添加   code   view   image   ima   UI   

   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

标签:nbsp   nal   select   添加   code   view   image   ima   UI   

原文地址:http://www.cnblogs.com/huzhenchao/p/6898914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!