UITabBarController
UITabBarController 是标签控制器,也是多视图控制器,只不过是它管理的视图控制器没有依赖关系和层级关系,是并列关系, 所有的视图控制器都是同时存在的,空间不会释放.
UITabBarController 也是自带一个view和显示内容以及下方的tabBar. tabBar是一组标签,每一个标签对应一个视图控制器,点击每一个标签会进行视图控制器的切换
//配置viewControllers
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//配置viewControllers
[self configViewControllers];
}
- (void)configViewControllers
{
//第一个
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
//title
firstNC.tabBarItem.title = @"主页";
//image
firstNC.tabBarItem.image = [UIImage imageNamed:@"53-house.png"];
//badgeValue
firstNC.tabBarItem.badgeValue = @"New";
//设置选中的图片
firstNC.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_home.png"];
//第二个
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:secondVC];
//title
secondNC.tabBarItem.title = @"团购";
//image
secondNC.tabBarItem.image = [UIImage imageNamed:@"80-shopping-cart.png"];
//第三个
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
UINavigationController *thirdNC = [[UINavigationController alloc] initWithRootViewController:thirdVC];
//title
thirdNC.tabBarItem.title = @"发现";
//image
thirdNC.tabBarItem.image = [UIImage imageNamed:@"12-eye.png"];
//第四个
FourthViewController *fourthVC = [[FourthViewController alloc] init];
UINavigationController *fourthNC = [[UINavigationController alloc] initWithRootViewController:fourthVC];
//title
fourthNC.tabBarItem.title = @"钱包";
//image
fourthNC.tabBarItem.image = [UIImage imageNamed:@"35-shopping-bag.png"];
//第五个
FifthViewController *fifthVC = [[FifthViewController alloc] init];
UINavigationController *fifthNC = [[UINavigationController alloc] initWithRootViewController:fifthVC];
//title
fifthNC.tabBarItem.title = @"收藏";
//image
fifthNC.tabBarItem.image = [UIImage imageNamed:@"28-star.png"];
//第六个
SixthViewController *sixVC = [[SixthViewController alloc] init];
UINavigationController *sixthNC = [[UINavigationController alloc] initWithRootViewController:sixVC];
//title
sixthNC.tabBarItem.title = @"工具箱";
//image
sixthNC.tabBarItem.image = [UIImage imageNamed:@"36-toolbox.png"];
//第七个
SeventhViewController *sevenVC = [[SeventhViewController alloc] init];
UINavigationController *seventhNC = [[UINavigationController alloc] initWithRootViewController:sevenVC];
//title
seventhNC.tabBarItem.title = @"设置";
//image
seventhNC.tabBarItem.image = [UIImage imageNamed:@"20-gear2.png"];
self.viewControllers = @[firstNC,secondNC,thirdNC,fourthNC,fifthNC,sixthNC,seventhNC];
[firstNC release];
[firstVC release];
[secondNC release];
[secondVC release];
[thirdNC release];
[thirdVC release];
}