UITabBarController

#import "RootViewController.h"
#import "FirstViewController.h"
#include "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
#import "FifthViewController.h"
#import "SixthViewController.h"
//经所有的页面放在, UITabBarController
@interface RootViewController : UITabBarController

@end


@interface RootViewController () <UITabBarControllerDelegate>

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tabBar.tintColor = [UIColor orangeColor];
    //下面最多只能有5个, 多的就会显示 more
    FirstViewController *firstVC = [[FirstViewController alloc] init];
    firstVC.tabBarItem.title = @"第一页";
    firstVC.tabBarItem.image = [UIImage imageNamed:@"home"];
    firstVC.tabBarItem.badgeValue = @"99";
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    secondVC.tabBarItem.title = @"联系人";
    secondVC.tabBarItem.image = [UIImage imageNamed:@"contact"];
    secondVC.tabBarItem.badgeValue = @"通知";

    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    thirdVC.tabBarItem.title = @"闹钟";
    thirdVC.tabBarItem.image = [UIImage imageNamed:@"naozhong"];

    FourthViewController *fourthVC = [[FourthViewController alloc] init];
    fourthVC.tabBarItem.title = @"陌陌";
    fourthVC.tabBarItem.image = [UIImage imageNamed:@"momo"];
    fourthVC.tabBarItem.badgeValue = @"22";

    FifthViewController *fifthVC = [[FifthViewController alloc] init];
    fifthVC.tabBarItem.title = @"麦克";
    fifthVC.tabBarItem.image = [UIImage imageNamed: @"maike"];

    SixthViewController *sixthVC = [[SixthViewController alloc] init
                                    ];
    sixthVC.tabBarItem.title = @"淘宝";
    sixthVC.tabBarItem.image = [UIImage imageNamed:@"taobao"];
    //数组 viewControllers
    self.viewControllers = @[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixthVC];


    [firstVC release];
    [secondVC release];
    [thirdVC release];
    [fourthVC release];
    [fifthVC release];
    [sixthVC release];

    //代理:(时刻, 什么时刻, 可以干什么)
    self. delegate = self;

    self.moreNavigationController.tabBarItem.badgeValue = @"33";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UITabBarControllerDelegate
//是否允许切换,
//参数1: 标签
//参数2: 当前选择的
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (viewController == tabBarController.viewControllers[2]) {
        return YES;
    }
    return YES;
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"%@",viewController);
    viewController.tabBarItem.badgeValue = nil;
        //该方法最常用
}

- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers {
    NSLog(@"将要开始修改 viewControllers");

}

- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed {
    NSLog(@"将要结束修改");
}

- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed {
    NSLog(@"已经结束修改");
}


- (UIInterfaceOrientationMask)tabBarControllerSupportedInterfaceOrientations:(UITabBarController *)tabBarController {
    return UIInterfaceOrientationMaskLandscape;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值