fixed issue with attributedText setting not working correctly

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-14 18:42:33 -05:00
parent d7435068a3
commit 547b03ac1c

View File

@ -108,14 +108,14 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
/// Key of whether or not updateView() is called in setNeedsUpdate() /// Key of whether or not updateView() is called in setNeedsUpdate()
open var shouldUpdateView: Bool = true open var shouldUpdateView: Bool = true
/// Will determine if a scaled font should be used for the font. /// Will determine if a scaled font should be used for the font.
open var useScaledFont: Bool = false { didSet { setNeedsUpdate() }} open var useScaledFont: Bool = false { didSet { setNeedsUpdate() }}
open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
/// Array of LabelAttributeModel objects used in rendering the text. /// Array of LabelAttributeModel objects used in rendering the text.
open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
/// TextStyle used on the this label. /// TextStyle used on the this label.
@ -135,20 +135,18 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
/// Text that will be used in the label. /// Text that will be used in the label.
private var _text: String! private var _text: String!
override open var text: String! { override open var text: String! {
get { _text } didSet {
set { _text = text
textSetMode = .text textSetMode = .text
_text = newValue setNeedsUpdate()
styleText(newValue)
} }
} }
///AttributedText that will be used in the label. ///AttributedText that will be used in the label.
override open var attributedText: NSAttributedString? { override open var attributedText: NSAttributedString? {
get { super.attributedText } didSet {
set {
textSetMode = .attributedText textSetMode = .attributedText
styleAttributedText(newValue) setNeedsUpdate()
} }
} }
@ -306,7 +304,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
lineBreakMode: lineBreakMode) lineBreakMode: lineBreakMode)
applyAttributes(mutableText) applyAttributes(mutableText)
// Set attributed text to match typography // Set attributed text to match typography
super.attributedText = mutableText super.attributedText = mutableText
} }
@ -322,7 +320,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
let mutableText = NSMutableAttributedString(attributedString: newValue) let mutableText = NSMutableAttributedString(attributedString: newValue)
applyAttributes(mutableText) applyAttributes(mutableText)
// Modify attributed text to match typography // Modify attributed text to match typography
super.attributedText = mutableText super.attributedText = mutableText
} }
@ -424,3 +422,5 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
} }
} }
} }