Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Last active August 6, 2020 18:55
Show Gist options
  • Save serhiybutz/188906a6a54570a5ce6ec602dbdd9a42 to your computer and use it in GitHub Desktop.
Save serhiybutz/188906a6a54570a5ce6ec602dbdd9a42 to your computer and use it in GitHub Desktop.
import UIKit
// MARK: - Highlighted Label Class
class HighlightedLabel: UILabel {
override func didMoveToWindow() {
// Subscribe to theme notifications
ThemeManager.shared.register(self)
super.didMoveToWindow()
}
}
extension HighlightedLabel: Themable {
/// Handles theme notifications receiving a new theme.
func applyTheme(_ theme: MyTheme) {
textColor = theme.settings.textColor
backgroundColor = theme.settings.highlightedBgColor
switch theme {
case .light:
text = "Light Mode"
case .dark:
text = "Dark Mode"
}
sizeToFit()
}
}
// MARK: - Demo View Controller Class
class DemoViewController: UIViewController {
@IBOutlet weak var highlightedLabel: HighlightedLabel!
override func viewDidLoad() {
super.viewDidLoad()
// Subscribe to theme notifications
ThemeManager.shared.register(self)
}
}
extension DemoViewController: Themable {
/// Handles theme notifications receiving a new theme.
func applyTheme(_ theme: MyTheme) {
view.backgroundColor = theme.settings.appBgColor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment