27

我正在尝试添加一个徽章警报标签,如所附屏幕截图中的标签。

在此处输入图像描述

我试图搜索标题、标签 uitabbar 项目,但我被卡住了。

任何建议表示赞赏。

4

1 回答 1

67

Xcode 7.2.1 斯威夫特 2.1.1

您只需为所需的 UITabBarItem 设置 badgeValue,如下所示:

tabBarController?.tabBar.items?[4].badgeValue = "1"   // this will add "1" badge to your fifth tab bar item


// or like this to apply it to your first tab
tabBarController?.tabBar.items?.first?.badgeValue = "1st"

// or to apply to your second tab
tabBarController?.tabBar.items?[1].badgeValue = "2nd"

// to apply it to your last tab
tabBarController?.tabBar.items?.last?.badgeValue = "Last"

要从 UITabBarItem 中删除徽章,只需向其添加 nil 值

tabBarController?.tabBar.items?.first?.badgeValue = nil
于 2015-04-18T17:35:59.573 回答