gpt4 book ai didi

ios - 如何用swift设置标签栏角标(Badge)?

转载 作者:IT王子 更新时间:2023-10-29 05:04:17 49 4
gpt4 key购买 nike

如何使用 swift 设置标签栏角标(Badge)?例如,当我收到消息图标上显示数字 1 的新消息时!我是否必须使用 UITabBarItem.swift 并在其中编写代码!我不太确定我该怎么做

谢谢!

最佳答案

如果您获得了对 tabBarController 的引用(例如来自 UIViewController),您可以执行以下操作:

if let tabItems = tabBarController?.tabBar.items {
// In this case we want to modify the badge number of the third tab:
let tabItem = tabItems[2]
tabItem.badgeValue = "1"
}

在 UITabBarController 中,它将是 tabBar.items 而不是 tabBarController?.tabBar.items

并删除角标(Badge):

tabItem.badgeValue = nil

关于ios - 如何用swift设置标签栏角标(Badge)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111413/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com