added the logic for a attributedText

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-10 14:44:42 -06:00
parent c150f1552b
commit 7f0da47036

View File

@ -51,7 +51,7 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
}
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
}
@ -105,11 +105,27 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
open var labelText: String? { didSet { didChange() }}
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() }}
open var errorText: String? { didSet { didChange() }}
@ -192,11 +208,14 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
if let labelText {
primaryLabel.textPosition = .left
primaryLabel.typograpicalStyle = .BoldBodyLarge
primaryLabel.text = labelText
primaryLabel.surface = surface
primaryLabel.disabled = disabled
primaryLabel.attributes = labelTextAttributes
primaryLabel.text = labelText
primaryLabel.isHidden = false
} else if labelAttributedText != nil {
primaryLabel.isHidden = false
} else {
primaryLabel.isHidden = true
}
@ -210,6 +229,10 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er
secondaryLabel.disabled = disabled
secondaryLabel.attributes = childTextAttributes
secondaryLabel.isHidden = false
} else if childAttributedText != nil {
secondaryLabel.isHidden = false
} else {
secondaryLabel.isHidden = true
}