美文网首页
第一天04-自定义子控制器

第一天04-自定义子控制器

作者: March_Cullen | 来源:发表于2017-03-28 17:54 被阅读0次
    // LYTabBarController.m
    // Created by younglee on **/**/**
    // Copyright (c) **** younglee. All rights reserved.
    
    #import "LYTabBarController.h"
    #import "LYFirstViewController.h"
    #import "LYSecondViewController.h"
    #import "LYThirdViewController.h"
    #import "LYFourthViewController.h"
    @implementation LYTabBarController
    
    - (void)initialize {
        NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
        normalAttrs[NSFontArrtibuteName] = [UIFont systemFontOfSize:12];
        normalAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
          NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
          selecteddAttrs[NSFontAttributeName] = [NSFont systemFontOfSize:12];
          selectedAttrs[NSForegroundAttributeName] = [UIColor darkGrayColor];
    
          [[UIAppearance appearance] setAttributes:normalAttrs forState:UIControlStateNormal];
          [[UIAppearance appearance] setAttributes:selectedAttrs forState:UIControlStateSelected];
    
    }
    - (void) viewDidLoad {
        [super viewDidLoad];
        [self setupChildVc:[LYFirstViewController class] withTitle:@"item01" imageNamed:@"image01" selectedImageNamed:@"selectedImage01"];
        [self setupChildVc:[LYSecondViewController class] withTitle:@"item02" imageNamed:@"image02" selectedImageNamed:@"selectedImage02"];
        [self setupChildVc:[LYThirdViewController class] withTitle:@"item03" imageNamed:@"image03" selectedImageNamed:@"selectedImage03"];
        [self setupChildVc:[LYFourthViewController class] withTitle:@"item04" imageNamed:@"image04" selectedImageNamed:@"selectedImage04"];
    }
    
    - (void)setupChildVc:(Class)class withTitle:(NSString *)title imageNamed:(NSString *)imageName selectedImageNamed:(NSString *)selectedImageName {
        UIViewController *vc = [[class alloc] init];
        vc.tabBarItem.title = title;
        vc.tabBarItem.image = [UIImage imagedNamed:imageName];
        vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
        vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
        [self addChildViewController:[[UINavigationController alloc] initWithRootViewController:vc]];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:第一天04-自定义子控制器

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