Day 13
AppDelegate.m
// 2. 设置根视图控制器
// 2.1 把将要添加到标签控制器中的视图控制器都创建
WeChatViewController *weChatVC = [[WeChatViewController new] autorelease];
weChatVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"WeChat" image:[UIImage imageNamed:@"item_normal@2x.png"] tag:101] autorelease];
ContactsViewController *contactsVC = [[ContactsViewController new] autorelease];
contactsVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:100] autorelease];
DiscoverViewController *discoverVC = [[DiscoverViewController new] autorelease];
discoverVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"Discover" image:[UIImage imageNamed:@"item_normal@2x.png"] selectedImage:[UIImage imageNamed:@"item_selected@2x.png"]] autorelease];
MeViewController *meVC = [[MeViewController new] autorelease];
meVC.tabBarItem = [[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:102] autorelease];
// 2.2 创建标签控制器
UITabBarController *rootTBC = [[[UITabBarController alloc] init] autorelease];
// 给标签控制器添加子控制器
rootTBC.viewControllers = @[weChatVC, contactsVC, discoverVC, meVC];
// 2.3 设置根视图控制器
self.window.rootViewController = rootTBC;
// 3. 设置UITabBar的一些常用属性
// 3.1 选中的渲染颜色
rootTBC.tabBar.tintColor = [UIColor redColor];
// 3.2 设置整体渲染颜色
rootTBC.tabBar.barTintColor = [UIColor purpleColor];
// 3.3 设置背景图片
rootTBC.tabBar.backgroundImage = [UIImage imageNamed:@"tab_bar_bg.png"];
// 3代表有3条新消息传来(即角标)
contactsVC.tabBarItem.badgeValue = @"3";
// 设置代理后,实现协议UITabBarControllerDelegate中的方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"%@", viewController);
// 点击哪个控制器,上面的提示信息就消失
viewController.tabBarItem.badgeValue = nil;
}