This file contains hidden or 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
let addItemNotfication = NSNotification.Name(rawValue: "addItem") |
This file contains hidden or 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
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)" | |
} |
This file contains hidden or 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
override func viewDidLoad() { | |
super.viewDidLoad() | |
// add badge to my cart tab icon with value of zero | |
self.tabBar.items![0].badgeValue = "0" | |
createObservers() | |
} |
This file contains hidden or 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() |
This file contains hidden or 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
NotificationCenter.default.post(name: addItemNotfication, object: nil,userInfo: nil) |
This file contains hidden or 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
deinit { | |
NotificationCenter.default.removeObserver(self) | |
} |
This file contains hidden or 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
class MainViewController: UIViewController { | |
@IBOutlet weak var changeButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
@IBAction func changeButtonDidTapped(_ sender: Any) { | |
let chooseVC = storyboard?.instantiateViewController(identifier: "chooseVC") as! ChooseViewController | |
chooseVC.modalPresentationStyle = .fullScreen |
This file contains hidden or 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
class ChooseViewController: UIViewController { | |
@IBOutlet weak var sunButton: SpaceCustomButton! | |
@IBOutlet weak var mercuryButton: SpaceCustomButton! | |
@IBOutlet weak var venusButton: SpaceCustomButton! | |
@IBOutlet weak var earthButton: SpaceCustomButton! | |
@IBOutlet weak var moonButton: SpaceCustomButton! | |
@IBOutlet weak var marsButton: SpaceCustomButton! | |
@IBOutlet weak var jupiterButton: SpaceCustomButton! | |
@IBOutlet weak var saturnButton: SpaceCustomButton! |
This file contains hidden or 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 | |
protocol ChoosePlanetMoonDelegate { | |
func didChoosePlanetWith(image: UIImage) | |
} |
This file contains hidden or 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
class MainViewController: UIViewController, ChoosePlanetMoonDelegate { | |
@IBOutlet weak var mainPlanetImage: UIImageView! | |
@IBOutlet weak var changeButton: UIButton! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
@IBAction func changeButtonDidTapped(_ sender: Any) { | |
let chooseVC = storyboard?.instantiateViewController(identifier: "chooseVC") as! ChooseViewController |
OlderNewer