效果展示
1. 签tarBar协议
目的点击时tabBarItem.badgeValue = nil
<UITabBarControllerDelegate>
2.设置
self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// 微信部分
RootViewController *rootVC = [[RootViewController alloc]init];
UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:rootVC];
// 设置内容
naVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"微信"image:[UIImage imageNamed:@"clock"] tag:1000];
// 提示信息
naVC.tabBarItem.badgeValue = @"1";
// 通讯录部分
firstViewController *firstVC = [[firstViewController alloc]init];
UINavigationController *firstnaVC = [[UINavigationController alloc]initWithRootViewController:firstVC];
firstnaVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"通讯录" image:[UIImage imageNamed:@"chat2"] selectedImage:[UIImage imageNamed:@"gear"]];
firstnaVC.tabBarItem.badgeValue = @"new";
// 第三部分
SecondViewController *secondVC = [[SecondViewController alloc]init];
UINavigationController *secondnaVC = [[UINavigationController alloc]initWithRootViewController:secondVC];
secondVC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem: UITabBarSystemItemBookmarks tag:10000];
secondVC.tabBarItem.badgeValue = @"99+";
// 标签视图控制器,用来管理导航控制器的
UITabBarController *tabBars = [[UITabBarController alloc]init];
// 设置背景颜色
tabBars.tabBar.barTintColor = [UIColor greenColor];
// 设置不半透明
tabBars.tabBar.translucent = NO;
// 设置选中按钮的颜色
tabBars.tabBar.tintColor = [UIColor blueColor];
// 给标签控制器指定子控制器
tabBars.viewControllers = [NSArray arrayWithObjects:naVC,firstnaVC,secondnaVC,nil];
self.window.rootViewController = tabBars;
[tabBars release];
tabBars.delegate = self;
3.实现tarBar协议方法
// 点击tabBar 上按钮时触发
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
NSLog(@"==%@",viewController);
UINavigationController *navc = (UINavigationController *)viewController;
navc.tabBarItem.badgeValue = nil;
}