快速设置UITabBarItem的Badge值 [英] Swift setting Badge Value for UITabBarItem
本文介绍了快速设置UITabBarItem的Badge值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加徽章警报标签,如所附屏幕快照中的标签.
I'm attempting to add a badge alert label like the one in the screenshot attached.
我尝试搜索标题,标签uitabbar项目,但被卡住了.
I've tried to search for titles, labels uitabbar items but I'm stuck.
任何建议都值得赞赏.
推荐答案
Xcode 7.2.1 Swift 2.1.1
您只需为所需的UITabBarItem设置badgeValue,如下所示:
You just have to set the badgeValue for your desired UITabBarItem as follow:
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值
To remove a badge from the UITabBarItem just add nil value to it
tabBarController?.tabBar.items?.first?.badgeValue = nil
这篇关于快速设置UITabBarItem的Badge值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文