From 89a4c5d397e7df17355d5869c14ac03445e12d69 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 8 Mar 2024 10:09:59 -0600 Subject: [PATCH] updated label with overrides for textColor and font Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index c998c70b..0c89ae3f 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -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)