// 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
网友评论