From 8490ef3572191d28aaa92bd7c5042f7cb03a4f22 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 13 Jan 2020 15:46:50 -0500 Subject: [PATCH] enabled/disabled colors. --- MVMCoreUI/Atoms/Buttons/Link.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/Link.swift b/MVMCoreUI/Atoms/Buttons/Link.swift index 4a23281b..04484307 100644 --- a/MVMCoreUI/Atoms/Buttons/Link.swift +++ b/MVMCoreUI/Atoms/Buttons/Link.swift @@ -16,6 +16,15 @@ import UIKit private var additionalData: [AnyHashable: Any]? + public var titleColor: (enabled: UIColor?, disabled: UIColor?) = (.mfTextButton(), .mfSilver()) + + public override var isEnabled: Bool { + didSet { + setTitleColor(isEnabled ? titleColor.enabled : titleColor.disabled, for: .normal) + setNeedsDisplay() + } + } + //-------------------------------------------------- // MARK: - Delegate //-------------------------------------------------- @@ -50,7 +59,7 @@ import UIKit let context = UIGraphicsGetCurrentContext() - // Set to the same color as the text + // Set line to the same color as the text if let color = titleLabel?.textColor?.cgColor { context?.setStrokeColor(color) } @@ -108,6 +117,7 @@ extension Link: MVMCoreViewProtocol { contentMode = .redraw setTitleColor(.mfTextButton(), for: .normal) setTitleColor(.mfCharcoal(), for: .highlighted) + titleColor = (.mfTextButton(), .mfSilver()) titleLabel?.numberOfLines = 1 titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.textAlignment = .left @@ -125,14 +135,15 @@ extension Link: MVMCoreUIMoleculeViewProtocol { public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { self.additionalData = additionalData self.delegateObject = delegateObject + buttonDelegate = delegateObject?.buttonDelegate guard let dictionary = json else { return } actionMap = dictionary - buttonDelegate = delegateObject?.buttonDelegate - - let color = dictionary.stringForkey(KeyTextColor) - setTitleColor(.mfGet(forHex: color), for: .normal) + if let colorHex = dictionary[KeyTextColor] as? String { + titleColor.enabled = .mfGet(forHex: colorHex) + setTitleColor(titleColor.enabled, for: .normal) + } if let title = dictionary.optionalStringForKey(KeyTitle) { setTitle(title, for: .normal)