#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;
}
UITabBarController
最新推荐文章于 2016-08-26 09:33:22 发布