- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
RedViewController *redVC = [RedViewController new];
UINavigationController *redNC = [[UINavigationController alloc]initWithRootViewController:redVC];
OrangeViewController *orangeVC = [OrangeViewController new];
UINavigationController *orangeNC = [[UINavigationController alloc]initWithRootViewController:orangeVC];
YellowViewController *yellowVC = [YellowViewController new];
UINavigationController *yellowNC = [[UINavigationController alloc]initWithRootViewController:yellowVC];
GreenViewController *greenVC = [GreenViewController new];
UINavigationController *greenNC = [[UINavigationController alloc]initWithRootViewController:greenVC];
CyanViewController *cyanVC = [CyanViewController new];
UINavigationController *cyanNC = [[UINavigationController alloc]initWithRootViewController:cyanVC];
BlueViewController *blueVC = [BlueViewController new];
UINavigationController *blueNC = [[UINavigationController alloc]initWithRootViewController:blueVC];
PurpleViewController *purpleVC = [PurpleViewController new];
UINavigationController *purpleNC = [[UINavigationController alloc]initWithRootViewController:purpleVC];
#pragma mark tabBarController
//准备视图控制器数组
NSArray *array = @[redNC,orangeNC,yellowNC,greenNC,cyanNC,blueNC,purpleNC];
//创建tabBarController
UITabBarController *tabBar = [[UITabBarController alloc]init];
//设定子视图控制器
tabBar.viewControllers = array;
//设置颜色,着色过程
tabBar.tabBar.tintColor = [UIColor magentaColor];
//设置条的颜色
tabBar.tabBar.barTintColor = [UIColor whiteColor];
//大小,高度:49
//设置样式
// tabBar.tabBar.barStyle = UIBarStyleDefault;
//设置背景颜色
// tabBar.tabBar.backgroundImage = [UIImage imageNamed:@"tabBar"];
//跟事件相关的属性
//默认选择的是哪一个
tabBar.selectedIndex = 3;
//设置badgeValue ---
redVC.tabBarItem.badgeValue = @"HOT";
orangeVC.tabBarItem.badgeValue = @"NEW";
//设置代理对象
tabBar.delegate = self;
//一键换肤(同一修改UI)--是一个单例
[[UINavigationBar appearance] setBarTintColor:[UIColor magentaColor]];
//指定为根视图控制器
[self.window setRootViewController:tabBar];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark UITabBarControllerDelegate
//应用场景比较少
//将要选中控制器执行的方法
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
//请求数据在这弄完
return YES;
}
//已经选中控制器执行的方法
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//请求页面在这
NSLog(@"");
}
=======================================
@implementation RedViewController
//M层数据写在初始化方法,每一个item都是M层
//初始化本身就是管理数据的。
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.title = @"red";
// self.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemSearch tag:1];
// self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"chat" image:[UIImage imageNamed:@"08-chat"] selectedImage: [UIImage imageNamed:@"09-chat2"]];
// //渲染
// UIImage *image = [UIImage imageNamed:@"kiss.jpg"];
// //渲染为原色版本
// image= [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//
// self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"pp" image:image tag:101];
// self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"clock" image:[UIImage imageNamed:@"11-clock"] tag:100];
UIImage *home = [UIImage imageNamed:@"iconfont-home"];
self.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:home tag:101];
}
return self;
}
//V层放在loadView中一种可以使用自己的view,一种就是使用自定义的view,需要一个指向。
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}