Created
September 1, 2019 21:56
-
-
Save MoussaHellal/e01e08ea34fd31fe8cacc5b07d33d2f7 to your computer and use it in GitHub Desktop.
TabBarController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TabBarController: UITabBarController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// add badge to my cart tab icon with value of zero | |
self.tabBar.items![0].badgeValue = "0" | |
createObservers() | |
} | |
func createObservers() { | |
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.setBadge(notification:)), name: addItemNotfication, object: nil) | |
} | |
@objc func setBadge(notification: NSNotification) { | |
//get the existant badge value | |
let badgeValue = Int(self.tabBar.items![0].badgeValue!)! | |
// set the new badge value | |
self.tabBar.items![0].badgeValue = "\(badgeValue + 1)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment