uttam
uttam

Reputation: 1364

how can i set the badge in tab bar in objective-c?

I want to put the notification in the tab bar of the app to show the number of item selected for the shopping list. Is there any way to add the notification in the tab bar of app.

Upvotes: 17

Views: 9057

Answers (4)

Ram Mishra
Ram Mishra

Reputation: 797

On the storyboard you have to select your navigation view controller if you have and then open your Property window and set Badge according to your requirement.

if you want to set programmatically

1. find your tabbar Item by viewcontroller

 # badge=what you want to set.   

2.[[[[self tabBarController] tabBar] items] objectAtIndex:1] setBadgeValue:badge];

and if you want to set by storyboard please refer this image.

enter image description here

Hope this will helps. Thanks


Also if you want to use in swift. Below code will work for you

[[self tabBarItem] setBadgeValue:@"42"];

Upvotes: 4

Hiren Dhamecha
Hiren Dhamecha

Reputation: 648

I did it using:

self.navigationController.tabBarItem.badgeValue = @"2";

Upvotes: 1

Ben Gottlieb
Ben Gottlieb

Reputation: 85532

You can set the badgeValue property on a UITabBarItem to present the user with a small red badge on that item.

Upvotes: 1

Dave DeLong
Dave DeLong

Reputation: 243156

You mean the badge? Do something like (where self is a UIViewController):

[[self tabBarItem] setBadgeValue:@"42"];

Upvotes: 33

Related Questions