1

在此处输入图像描述

这里我使用 4 个 tabViews,第三个是聊天按钮,所以这里用户未读消息如何显示徽章

在#import "HomeTabViewController.h"

 - (void)viewDidLoad {
  [super viewDidLoad];
    NSString *badgeVal = @"5";
  [[[[self.tabBarController viewControllers] objectAtIndex:2]  tabBarItem] setBadgeValue:badgeVal];
  }
4

3 回答 3

4

您需要为此简单地设置badgeValue属性tabBarItem

NSString *badgeVal = @"5"; //Unread message count
[[[[self.tabBarController viewControllers] objectAtIndex:2] tabBarItem] setBadgeValue:badgeVal];

注意:我可以使用第 3 次访问ViewControllerobjectAtIndex:2因为您想为第 3 次设置徽章UITabBarItem

于 2017-01-21T06:23:37.880 回答
1

好吧,只需使用 的badgeValue属性UITabbarItem

https://developer.apple.com/reference/uikit/uitabbaritem/1617065-badgevalue

于 2017-01-21T06:25:27.283 回答
1

尝试这个。

NSString *badgeVal = @"5"; //Unread message count
[[self navigationController] tabBarItem].badgeValue = badgeVal;

或者

[[self.tabBarController.tabBar.items objectAtIndex:<your item position>] setBadgeValue:[NSString stringWithFormat:@"%d",badgeVal]];

于 2017-01-21T06:50:02.503 回答