Here i am using the 4 tabViews, third one is chat button so here user unread messages how to show the badges
in #import "HomeTabViewController.h"
- (void)viewDidLoad {
[super viewDidLoad];
NSString *badgeVal = @"5";
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];
}
You need to simply set badgeValue
property of tabBarItem
for that.
NSString *badgeVal = @"5"; //Unread message count
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];
Note : I have access 3rd ViewController
using objectAtIndex:2
because you want to set badge for the 3rd UITabBarItem
.
Well, just use the badgeValue
property of the UITabbarItem
:
https://developer.apple.com/reference/uikit/uitabbaritem/1617065-badgevalue
Try this.
NSString *badgeVal = @"5"; //Unread message count
[[self navigationController] tabBarItem].badgeValue = badgeVal;
or
[[self.tabBarController.tabBar.items objectAtIndex:<your item position>] setBadgeValue:[NSString stringWithFormat:@"%d",badgeVal]]
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.