先找到需要设置角标的tabbarItem。然后赋值badgeValue,如果想要隐藏的时候只需要把设置tabarItem.badgeValue=nil; 即可。
UITabBarController * root = self.tabBarController; // self当前的viewController
UITabBarItem * tabBarItem = [UITabBarItem new];
if (root.tabBar.items.count>4) {
tabBarItem = root.tabBar.items[3];// 拿到需要设置角标的tabarItem
}
NSString *rst = [NSString stringWithFormat:@"100"];
int a = [rst intValue];
if (a == 0) {
[tabBarItem setBadgeValue:nil];// 隐藏角标
}else if (a > 99) {
[tabBarItem setBadgeValue:@"99+"];
} else {
[tabBarItem setBadgeValue:rst];
}