先找到需要設置角標的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];
}
