TabBar——APP中下面的“导航” 界面跳转

87 篇文章 0 订阅

- (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];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值