//
//  AppDelegate.m
//  TabBarControllerDemo
//
//  Created by qianfeng on 15/9/22.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController1.h"
#import "ViewController2.h"
#import "ViewController3.h"
#import "ViewController4.h"
#import "ViewController5.h"
#import "ViewController6.h"
#import "ViewController7.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

#pragma mark    ------------------------创建customTabBar
- (void)customTabBar
{
    //取出分栏控制器
    UITabBarController *vc = (id)self.window.rootViewController;
    
    //bar样式
    vc.tabBar.barStyle = UIBarStyleBlack;
    
    //半透明度
    vc.tabBar.translucent = NO;
    
    //tint color是设置你选中的那个tabBar的颜色,默认是蓝色
    vc.tabBar.tintColor = [UIColor greenColor];
    
    //bar tint color
    vc.tabBar.barTintColor = [UIColor whiteColor];
    
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

#pragma mark    ------------------------VC1
    
    ViewController1 *vc1 = [[ViewController1 alloc] init];
    
    vc1.title = @"微信";
    
    //vc1.view.backgroundColor = [UIColor whiteColor];
    
    vc1.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
    
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"home" image:[UIImage imageNamed:@"tabbar_mainframeHL@2x"] tag:2];
    
    //创建导航控制器
    UINavigationController *nvc1 = [[UINavigationController alloc]initWithRootViewController:vc1];

nvc1.navigationBar.barStyle = UIBarStyleBlack;
    
    //nvc1.navigationBar.barTintColor = [UIColor redColor];
    
    nvc1.navigationBar.tintColor = [UIColor yellowColor];//字体颜色
    
   //nvc1.navigationBar.translucent = NO;
    
    #pragma mark    ------------------------VC2
    
    ViewController2 *vc2 = [[ViewController2 alloc] init];
    
    vc2.title = @"通讯录";
    
    vc2.view.backgroundColor = [UIColor whiteColor];
    
    vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通讯录" image:[UIImage imageNamed:@"tabbar_contactsHL@2x"] tag:2];
    
    //创建导航控制器
    UINavigationController *nvc2 = [[UINavigationController alloc]initWithRootViewController:vc2];
    
    nvc2.navigationBar.tintColor = [UIColor whiteColor];
    
    nvc2.navigationBar.barStyle = UIBarStyleBlack;//背景是黑色
    
    #pragma mark    ------------------------VC3
    
    ViewController3 *vc3 = [[ViewController3 alloc] init];
    
    vc3.title = @"发现";
    
    vc3.view.backgroundColor = [UIColor whiteColor];
    
    vc3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"tabbar_discover@2x"] selectedImage:[UIImage imageNamed:@"tabbar_discoverHL@2x"]];
    
    vc3.tabBarItem.tag = 3;
    
    
    //创建导航控制器
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:vc3];
    
    nvc.navigationBar.barStyle = UIBarStyleBlack;//背景是黑色
    
    #pragma mark    ------------------------VC4
    
    ViewController4 *vc4 = [[ViewController4 alloc] init];
    
    vc4.title = @"我";
    
    vc4.view.backgroundColor = [UIColor whiteColor];
    
    vc4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"tabbar_me@2x"] tag:4];
    
    //创建导航控制器
    UINavigationController *nvc4 = [[UINavigationController alloc]initWithRootViewController:vc4];
    
    nvc4.navigationBar.barStyle = UIBarStyleBlack;//背景是黑色
    
    #pragma mark    ------------------------VC5
    
    ViewController5 *vc5 = [[ViewController5 alloc] init];
    
    vc5.title = @"页五";
    
    vc5.view.backgroundColor = [UIColor cyanColor];
    
    vc5.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:5];
    
    #pragma mark    ------------------------VC6
    
    ViewController6 *vc6 = [[ViewController6 alloc] init];
    
    vc6.title = @"页六";
    
    vc6.view.backgroundColor = [UIColor orangeColor];
    
    vc6.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:6];
    
    #pragma mark    ------------------------VC7
    
    ViewController7 *vc7 = [[ViewController7 alloc]init];
    
    vc7.title = @"页七";
    
    vc7.view.backgroundColor = [UIColor blueColor];
    vc7.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:7];
    
    #pragma mark    ------------------------创建分栏目控制器等
    
    //分栏控制器 最多能显示五个
    UITabBarController *tvc = [[UITabBarController alloc]init];
    
    tvc.viewControllers = @[nvc1,nvc2,nvc,nvc4];//,vc5,vc6,vc7
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds] ];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    
    self.window.rootViewController = tvc;
    
    [self customTabBar];         //创建分栏控制器
    
    //设定代理
    tvc.delegate = self;
    
    //设置选择控制器
    tvc.selectedIndex = 0;
    
//    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
//    
//    NSString * value = [ud objectForKey:@"title"];
//    
//    for (UIViewController *vc in tvc.viewControllers) {
//        if ([vc.title isEqualToString:value]) {
//            tvc.selectedViewController = vc;
//        }
//    }
    
    //NSLog(@"%@",NSHomeDirectory());
    
    [self.window makeKeyAndVisible];
    
    
    return YES;
}

#pragma mark    ------------------------ 实现分栏控制器代理方法
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewControll{
    
    //是否可以选择这个控制器,yes 允许选择,no 不允许
//    if (viewControll.tabBarItem.tag == 2) {
//        return NO;
//    }
//    
    return YES;
    
}

- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
    //将要开始编辑的时候,会调用这个方法
    for (UIViewController *vc in viewControllers) {
        
        NSLog(@"tag = %ld",vc.tabBarItem.tag);
        
    }
    
}

- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
{
    //编辑结束的时候会调用这个方法
    for (UIViewController *vc in viewControllers) {
        
        NSLog(@"changed tag = %ld",vc.tabBarItem.tag);
        
    }
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    //选择视图控制器之后,调用这个方法
    NSLog(@"vc tag = %ld",viewController.tabBarItem.tag);
    
    //是一个单例
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    
    [ud setObject:viewController.title forKey:@"title"];
    
    //写入文件
    [ud synchronize];
}

@end

分栏控制器和导航栏目tabBarItem,UINavigationController的更多相关文章

  1. 设置TabBar分栏控制器上图片的大小问题

    我们都知道,iOS因为屏幕分辨率的问题,UID在交付我们iOS开发人员程序配图的时候,一般是三套图,分别对应三种不同的分辨率,对不同size的屏幕系统会自动使用不同像素的图片,我们只需要在命名时给三套 ...

  2. CSS3-column分栏

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. css笔记 - column分栏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 导航栏控制器和标签栏控制器(UINavigationController和UITabBarController)混用

    很多时候,在UI设计方面同时需要使用导航控制器和标签栏控制器,这时,需要掌握如何设计结合使用这两种不同控制器.比如手机QQ,程序有三个标签 栏(分别为消息.联系人.动态),同时在选择某个联系人或者会话 ...

  5. iOS:视图切换的第二种方式:UINavigationController导航栏控制器

    UINavigationController:一个以栈的形式管理多视图的容器,负责子控制器之间的跳转.由于以栈的方式管理视图,各个视图的切换就是压栈和出栈操作,所以出栈后的视图会立即销毁. 介绍: & ...

  6. 简单仿京东"筛选"界面 双导航栏控制器共存 by Nicky.Tsui

    大概就是这么一个效果 如图.大概可以看到,"筛选"视图后面有一层视图盖住了后面原来的视图 那么我们可以通过加一个view到导航栏控制器的view里面来实现 //该view作为全局变 ...

  7. UINavigationController导航控制器初始化 导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最下面,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

  8. 选项卡栏控制器(UITabBarController)

    选项卡栏控制器管理的每个场景都包含一个UITabBarItem,它包含标题.图像和徽章. 在场景里可以通过tabBarItem属性来获得UITabBarItem的引用.例如:[self.tabBarI ...

  9. iOS开发UI篇—多控制器和导航控制器简单介绍

    iOS开发UI篇—多控制器和导航控制器简单介绍 一.多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单.当app中有多个控制器的时候,我们就需要对这些控制器进行管理 有多个vi ...

随机推荐

  1. C# 仿制QQ弹出新闻消息框

    打开QQ的时候,QQ新闻弹出窗体在屏幕的右下角就会慢慢升起一个小窗口,占用的地方不大,可以起到提示的作用.下面就让我们来看看,怎样用系统API来轻松实现这个功能. API原型函数: bool Anim ...

  2. sqlserver 各种判断是否存在(表名、函数、存储过程等)

    库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists'elseprint 'not ex ...

  3. Properties 转换成Map

    转自:http://feitianbenyue.iteye.com/blog/1759259 对于Properties 转换成Map 的问题: 第一时间想到的肯定有以下: 1.  迭代出来  再 pu ...

  4. iOS开发——路径篇&混编路径与全局宏路径

    混编路径与全局宏路径 最近在做东西的时候有一个地方要用到一个第三方库的,但是目前swift版的还没有找到,自己又不想写(其实是不会写),所以就想到了混编,但是中间出现了好多问题,其中印象最深的就是桥接 ...

  5. 已解决】Sublime中运行带input或raw_input的Python代码出错:EOFError: EOF when reading a line(转)

    [问题] 在折腾: [已解决]Sublime Text 2中运行Python程序出错:The system cannot find the file specified 的过程中,虽然解决了找不到py ...

  6. 线性表 及Java实现 顺序表、链表、栈、队列

    数据结构与算法是程序设计的两大基础,大型的IT企业面试时也会出数据结构和算法的题目, 它可以说明你是否有良好的逻辑思维,如果你具备良好的逻辑思维,即使技术存在某些缺陷,面试公司也会认为你很有培养价值, ...

  7. 高级Swing——列表

    1. 列表 1.1 JList构件 JList可以将多个选项放置在单个框中.为了构建列表框,首先需要创建一个字符串数组,然后将这个数组传递给JList构造器. String[] words= { &q ...

  8. LINUX内核源代码情景分析

    http://pan.baidu.com/s/1sjIwswP

  9. 如何制作gif动画,丰富自己的博客?

    不久前在博客园上看到有个哥们发表了一篇博客,其中使用了大量的动态的gif动画,感觉这种方法对于丰富博客内容非常有帮助,然后在网上搜索了一些关于制作gif动画的资料.我的方法不一定好,在这里仅作为抛砖引 ...

  10. 解决faststone capture在台式机上录制屏幕视频没有声音的问题

    点击屏幕录像机: 在弹出的屏幕录像机窗口中选择录制音频,然后点击选项按钮: 在弹出的选项按钮中选择视频选项,将所有的多选框都选中,注:最后一个选项录制windows XP的工具提示最好也选上,我发现如 ...