diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 10ad74dd..1ebe425e 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -45,10 +45,29 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt } // By default, it will follow most of the font standard in zepplin, and should need to be changed - public var normalTextFont: UIFont? = MFStyler.fontB2() - public var actionTextFont: UIFont? = MFStyler.fontB2() - public var normalTextColor: UIColor = .black - public var actionTextColor: UIColor = .black + public var normalTextFont: UIFont? = MFStyler.fontB2() { + didSet(newNormalFont) { + setAlternateNormalTextAttributes([NSAttributedString.Key.font: newNormalFont as Any]) + } + } + + public var actionTextFont: UIFont? = MFStyler.fontB2() { + didSet(newActionFont) { + setAlternateActionTextAttributes([NSAttributedString.Key.font: newActionFont as Any]) + } + } + + public var normalTextColor: UIColor = .black { + didSet(newNormalColor) { + setAlternateNormalTextAttributes([NSAttributedString.Key.foregroundColor: newNormalColor as Any]) + } + } + + public var actionTextColor: UIColor = .black { + didSet(newActionColor) { + setAlternateActionTextAttributes([NSAttributedString.Key.foregroundColor: newActionColor as Any]) + } + } public var makeWholeViewClickable = false @@ -333,7 +352,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt // MARK: - Helper //------------------------------------------------------ - private func getTextFromStringComponents() -> String? { + private func getTextFromStringComponents() -> String { if let frontTxt = frontText, !frontTxt.isEmpty { frontText?.append(" ") @@ -392,32 +411,27 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt private func setText(_ text: String?, startTag: String?, endTag: String?) { - guard let actionRange: ActionIndiciesTuple = rangeOfText(text, startTag: startTag, endTag: endTag) else { return } + let actionRange: ActionIndiciesTuple = rangeOfText(text, startTag: startTag, endTag: endTag) + + frontText = actionRange.revisedText if let revisedText = actionRange.revisedText, let startBraceIndex = actionRange.startIndex, let endBraceIndex = actionRange.endIndex { - + // TODO: Put some of this into a String Extension in MVMCore frontText = String(revisedText[revisedText.startIndex.. ActionIndiciesTuple? { + private func rangeOfText(_ text: String?, startTag: String?, endTag: String?) -> ActionIndiciesTuple { var fullText = text ?? "" - - guard let start = startTag, let end = endTag else { return nil } - - if !fullText.contains(Character(start)) && !fullText.contains(Character(end)) { - return nil - } - var actionRange: ActionIndiciesTuple - if let leftBrace = startTag, let rightBrace = endTag { + if let leftBrace = startTag, let rightBrace = endTag, fullText.contains(Character(leftBrace)) && fullText.contains(Character(rightBrace)) { actionRange.startIndex = fullText.firstIndex(of: Character(leftBrace)) fullText = fullText.replacingOccurrences(of: leftBrace, with: "") @@ -427,6 +441,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt self.text = fullText actionRange.revisedText = fullText + return actionRange }