How to set the tab bar badge with swift ? for example when I get new message showing number 1 on the message icon ! Do I have to use the UITabBarItem.swift and write the code in it ! I'm not really sure how I can do it
Thank you !
The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.
If you got the reference to the tabBarController (e.g. from the UIViewController) you can do the following:
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" }
From a UITabBarController it would be tabBar.items
instead of tabBarController?.tabBar.items
and to delete the badge:
tabItem.badgeValue = nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With