How to set badge value in Tab bar? How to set badge value in Tab bar? xml xml

How to set badge value in Tab bar?


Let me tell you the simplest way to set badge value :

[[self navigationController] tabBarItem].badgeValue = @"YourBadgeValue";


Vineet Singh's answer is good if you want to change the badge for the current tab. If instead you need to change the value for another tab you have in your tab bar, use the following:

Objective-C

[[self.tabBarController.tabBar.items objectAtIndex:0] setBadgeValue:nil];

Swift

tabBarController?.tabBar.items?[0].badgeValue = nil

Remember to replace the index I used with the actual tab you want to edit the value for.


AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];UITabBarItem *tbItem = (UITabBarItem *)[appDelegate.tabBarController.tabBar.items objectAtIndex:tabIndex];tbItem.badgeValue = [NSString stringWithFormat:@"%i", count];