refactored radiobox/radiobutton to have attributedText override

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-10 14:51:41 -06:00
parent 7f0da47036
commit 92c8c1073f
2 changed files with 57 additions and 1 deletions

View File

@ -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
}

View File

@ -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
}