From 92c8c1073fd95254248530ed88b6fdbeb10fb5b3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 14:51:41 -0600 Subject: [PATCH] refactored radiobox/radiobutton to have attributedText override Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBox.swift | 32 ++++++++++++++++++++ VDS/Components/RadioButton/RadioButton.swift | 26 +++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 2bb90be9..2893c0a9 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -95,14 +95,38 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ open var textAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var textAttributedText: NSAttributedString? { + didSet { + textLabel.useAttributedText = !(textAttributedText?.string.isEmpty ?? true) + textLabel.attributedText = textAttributedText + didChange() + } + } + open var subText: String? { didSet { didChange() }} open var subTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var subTextAttributedText: NSAttributedString? { + didSet { + subTextLabel.useAttributedText = !(subTextAttributedText?.string.isEmpty ?? true) + subTextLabel.attributedText = subTextAttributedText + didChange() + } + } + open var subTextRight: String? { didSet { didChange() }} open var subTextRightAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var subTextRightAttributedText: NSAttributedString? { + didSet { + subTextRightLabel.useAttributedText = !(subTextRightAttributedText?.string.isEmpty ?? true) + subTextRightLabel.attributedText = subTextRightAttributedText + didChange() + } + } + open var strikethrough: Bool = false { didSet { didChange() }} open var inputId: String? { didSet { didChange() }} @@ -191,6 +215,10 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ subTextLabel.disabled = disabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false + + } else if subTextAttributedText != nil { + subTextLabel.isHidden = false + } else { subTextLabel.isHidden = true } @@ -204,6 +232,10 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ subTextRightLabel.disabled = disabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false + + } else if subTextAttributedText != nil { + subTextRightLabel.isHidden = false + } else { subTextRightLabel.isHidden = true } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index afcd69e1..c2938af9 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -59,7 +59,7 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, } private var shouldShowLabels: Bool { - guard labelText?.isEmpty == false || childText?.isEmpty == false else { return false } + guard labelText?.isEmpty == false || childText?.isEmpty == false || labelAttributedText?.string.isEmpty == false || childAttributedText?.string.isEmpty == false else { return false } return true } @@ -111,9 +111,25 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var labelTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + open var labelAttributedText: NSAttributedString? { + didSet { + primaryLabel.useAttributedText = !(labelAttributedText?.string.isEmpty ?? true) + primaryLabel.attributedText = labelAttributedText + didChange() + } + } + open var childText: String? { didSet { didChange() }} open var childTextAttributes: [any LabelAttributeModel]? { didSet { didChange() }} + + open var childAttributedText: NSAttributedString? { + didSet { + secondaryLabel.useAttributedText = !(childAttributedText?.string.isEmpty ?? true) + secondaryLabel.attributedText = childAttributedText + didChange() + } + } open var showError: Bool = false { didSet { didChange() }} @@ -202,6 +218,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, primaryLabel.disabled = disabled primaryLabel.attributes = labelTextAttributes primaryLabel.isHidden = false + + } else if labelAttributedText != nil { + primaryLabel.isHidden = false + } else { primaryLabel.isHidden = true } @@ -215,6 +235,10 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, secondaryLabel.disabled = disabled secondaryLabel.attributes = childTextAttributes secondaryLabel.isHidden = false + + } else if childAttributedText != nil { + secondaryLabel.isHidden = false + } else { secondaryLabel.isHidden = true }