Last active
August 6, 2020 18:55
-
-
Save serhiybutz/188906a6a54570a5ce6ec602dbdd9a42 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 | |
// 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