From 61e843f8f806fca028c176485b09f9a70f3a9614 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 21 Jul 2023 10:43:36 -0500 Subject: [PATCH] added check for change of scaledFonts Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/ButtonBase.swift | 3 +++ VDS/Components/Label/Label.swift | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index c27a4a06..a3bd1941 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -53,6 +53,8 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open var attributes: [any LabelAttributeModel]? { nil } + open var useScaledFont: Bool = false { didSet { setNeedsUpdate() }} + open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var userInfo = [String: Primitive]() @@ -177,6 +179,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab //create the primary string let mutableText = NSMutableAttributedString.mutableText(for: text ?? "No Text", textStyle: textStyle, + useScaledFont: useScaledFont, textColor: textColor, alignment: titleLabel?.textAlignment ?? .center, lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 5b0b6ffb..203e669d 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -27,6 +27,8 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { open var useAttributedText: Bool = false + open var useScaledFont: Bool = false { didSet { setNeedsUpdate() }} + open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} @@ -89,6 +91,13 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- open func initialSetup() { if !initialSetupPerformed { + //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 @@ -135,6 +144,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { //create the primary string let mutableText = NSMutableAttributedString.mutableText(for: text, textStyle: textStyle, + useScaledFont: useScaledFont, textColor: textColorConfiguration.getColor(self), alignment: textPosition.textAlignment, lineBreakMode: lineBreakMode)