Last active
August 6, 2020 06:53
-
-
Save serhiybutz/a349b77e3662dac2787860b319a8d6ea to your computer and use it in GitHub Desktop.
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 DemoViewController: UIViewController { | |
@IBOutlet weak var highlightedLabel: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Subscribe this instance of UIViewController to theme notifications | |
ThemeManager.shared.register( | |
target: self, | |
action: DemoViewController.applyTheme) | |
// Subscribe `highlightedLabel` instance of UILabel to theme notifications | |
ThemeManager.shared.register( | |
target: highlightedLabel, | |
action: UILabel.applyHighlightedLabelTheme) | |
} | |
} | |
extension DemoViewController { | |
/// Handles theme notifications receiving a new theme. | |
fileprivate func applyTheme(_ theme: MyTheme) { | |
view.backgroundColor = theme.settings.appBgColor | |
} | |
} | |
extension UILabel { | |
/// Handles theme notifications receiving a new theme. | |
fileprivate func applyHighlightedLabelTheme(_ theme: MyTheme) { | |
switch theme { | |
case .light: | |
text = "Light Mode" | |
case .dark: | |
text = "Dark Mode" | |
} | |
textColor = theme.settings.textColor | |
backgroundColor = theme.settings.highlightedBgColor | |
sizeToFit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment