提问人:Sunil Targe 提问时间:5/3/2023 更新时间:5/4/2023 访问量:188
如何在iOS Swift中将绿点徽章设置为特定的tabBarItem?
How to set green dot badge to a particular tabBarItem in iOS Swift?
问:
目前,我正在尝试以这种方式设置绿点,但最终结果始终是红色徽章。
xxxx.tabBarItem.badgeColor = .clear
xxxx.tabBarItem.badge value = "●"
let attribute : [NSAttributedString.Key : Any] = [NSAttributedString.Key.foregroundColor : UIColor.green]
xxxx.tabBarItem.setBadgeTextAttributes(attribute, for: .disabled)
xxxx.tabBarItem.setBadgeTextAttributes(attribute, for: .selected)
xxxx.tabBarItem.setBadgeTextAttributes(attribute, for: .highlighted)
xxxx.tabBarItem.setBadgeTextAttributes(attribute, for: .normal)
我想要什么?
答:
0赞
Supriyo Dey
5/3/2023
#1
它会起作用的。使用代替 .tabBar.items
tabBarItem.badgeValue
self.tabBarController?.tabBar.items?[0].badgeColor = .clear
self.tabBarController?.tabBar.items?[0].badgeValue = "●"
let attribute : [NSAttributedString.Key : Any] = [NSAttributedString.Key.foregroundColor : UIColor.green]
self.tabBarController?.tabBar.items?[0].setBadgeTextAttributes(attribute, for: .disabled)
self.tabBarController?.tabBar.items?[0].setBadgeTextAttributes(attribute, for: .selected)
self.tabBarController?.tabBar.items?[0].setBadgeTextAttributes(attribute, for: .highlighted)
self.tabBarController?.tabBar.items?[0].setBadgeTextAttributes(attribute, for: .normal)
评论
badgeColor = .green
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)