updated label with overrides for textColor and font

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-08 10:09:59 -06:00
parent 23f3f8b6bf
commit 89a4c5d397

View File

@ -131,32 +131,43 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
/// Line break mode for the label, default is set to word wrapping.
open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }}
private var _text: String?
/// Text that will be used in the label.
override public var text: String! {
override open var text: String! {
get { super.text }
set {
// When text is set, we may need to re-style it as attributedText
// with the correct paragraph style to achieve the desired line height.
textSetMode = .text
attributes?.removeAll()
styleText(newValue)
}
}
///AttributedText that will be used in the label.
override public var attributedText: NSAttributedString? {
override open var attributedText: NSAttributedString? {
get { super.attributedText }
set {
// When text is set, we may need to re-style it as attributedText
// with the correct paragraph style to achieve the desired line height.
textSetMode = .attributedText
styleAttributedText(newValue)
}
}
override open var font: UIFont! {
didSet {
if let font, initialSetupPerformed {
textStyle = TextStyle.convert(font: font)
}
setNeedsUpdate()
}
}
override open var textColor: UIColor! {
didSet {
if let textColor, initialSetupPerformed {
textColorConfiguration = SurfaceColorConfiguration(textColor, textColor).eraseToAnyColorable()
}
setNeedsUpdate()
}
}
/// Whether the View is enabled or not.
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
@ -175,13 +186,13 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
//--------------------------------------------------
open func initialSetup() {
if !initialSetupPerformed {
initialSetupPerformed = true
//register for ContentSizeChanges
NotificationCenter
.Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification)
.sink { [weak self] notification in
self?.setNeedsUpdate()
}.store(in: &subscribers)
backgroundColor = .clear
numberOfLines = 0
lineBreakMode = .byWordWrapping
@ -307,7 +318,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
return
}
var mutableText = NSMutableAttributedString(attributedString: newValue)
let mutableText = NSMutableAttributedString(attributedString: newValue)
applyAttributes(mutableText)