Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Last active August 6, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serhiybutz/a349b77e3662dac2787860b319a8d6ea to your computer and use it in GitHub Desktop.
Save serhiybutz/a349b77e3662dac2787860b319a8d6ea to your computer and use it in GitHub Desktop.
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