Swift setting Badge Value for UITabBarItem

∥☆過路亽.° 提交于 2019-12-18 03:02:23

问题


I'm attempting to add a badge alert label like the one in the screenshot attached.

I've tried to search for titles, labels uitabbar items but I'm stuck.

Any suggestion is appreciated.


回答1:


Xcode 7.2.1 Swift 2.1.1

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"

To remove a badge from the UITabBarItem just add nil value to it

tabBarController?.tabBar.items?.first?.badgeValue = nil


来源:https://stackoverflow.com/questions/29719972/swift-setting-badge-value-for-uitabbaritem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!