How to set a badge value on a UITabBarController item

Screen Shot 2014-04-21 at 08.53.48

Each view controller has access to a UITabBarItem. This is only displayed if the current view controller is part of a UITabBarController. A UITabBarItem has a badge value which is that little red mark above icon and name to the tab bar item itself (as shown in the screenshot above: LIVE is currently the badgeValue of the tab bar item).

Here’s how you can set the badge value:

// set the tab bar value (any NSString will work):
self.tabBarItem.badgeValue = @"LIVE";

// make it disappear again
self.tabBarItem.badgeValue = nil;

// set it to a little red circle (no value, just an empty string)
self.tabBarItem.badgeValue = @"";

This approach will work if you have direct access to the class in the view controller. More commonly though you’ll have your own class embedded in a UINavigationController, in which case its tab bar item (and title) is shown on that tab.

In which case you can access the tab bar item like this:

// set badge value on your own nav controller
self.navigationController.tabBarItem.badgeValue = @"LIVE";




Leave a Reply