专栏名称: Adrenine
iOS开发
目录
相关文章推荐
51好读  ›  专栏  ›  Adrenine

iOS控件之UITabBarController

Adrenine  · 掘金  ·  · 2017-12-13 08:46

正文

#import "XBYTabBarController.h"
#import "ViewController.h"

@interface XBYTabBarController ()

@end

@implementation XBYTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addAllChildControllers];
    [self setupAllTabBarItem];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addAllChildControllers{
    ViewController *vc = [ViewController new];
    
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav1];
    
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav2];
    
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav3];
    
    UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav4];
}

-(void)setupAllTabBarItem {
    NSArray *title = @[@"1",@"2",@"3",@"4"];
    NSArray *image = @[@"1",@"2",@"3",@"4"];
    for (int i = 0;i<self.childViewControllers.count;i++){
        UINavigationController *nav = self.childViewControllers[i];
        nav.tabBarItem.title = title[i];
        nav.tabBarItem.image = [UIImage imageNamed:image[i]];
        nav.tabBarItem.selectedImage = [UIImage imageNamed:image[i]];
       
        NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
        mDic[NSForegroundColorAttributeName] = [UIColor redColor];
        //可以设置字体大小、颜色、阴影、空心图文混排等,详见NSAttributedString.h文件
        [nav.tabBarItem set






请到「今天看啥」查看全文