// 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-自定义子控制器
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
- 不管是安卓的官方文档还是源码注释,处处可见“从 Activity A 跳到 Activity B,当系统内存不足时...