From 8a861077dd824a3af4a6c162ceefa56ac4f8d991 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 23 Feb 2021 14:56:23 -0500 Subject: [PATCH] styler additon. label width value --- .../Atomic/Atoms/Views/Label/Label.swift | 4 +++- MVMCoreUI/Styles/Styler.swift | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 7e902d435..8838966c 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -594,7 +594,6 @@ public typealias ActionBlock = () -> () attributedText = attributedString } - @objc public func updateView(_ size: CGFloat) { scaleSize = size as NSNumber @@ -624,6 +623,9 @@ public typealias ActionBlock = () -> () } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0), let sizeObject = sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { font = font.updateSize(sizeObject.getValueBased(onSize: size)) } + + // Provide the label additional size information to help calculate its intrinsic content. + preferredMaxLayoutWidth = Styler.maxAvailableLayoutWidth(size: size) } @objc public func setFont(_ font: UIFont, scale: Bool) { diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index c0dd6792..b2614f04 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -209,7 +209,29 @@ open class Styler { } open class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { - return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size + sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size + } + + open class func defaultHorizontalPadding(for size: CGFloat) -> CGFloat { + sizeObject(withScalingStandardSize: CGFloat(Padding.Component.horizontalPaddingForApplicationWidth)).getValueBased(onSize: size) + } + + open class func defaultVerticalPadding(for size: CGFloat) -> CGFloat { + sizeObject(withScalingStandardSize: CGFloat(Padding.Component.verticalPaddingForApplicationWidth)).getValueBased(onSize: size) + } + + open class func sizeObject(withScalingStandardSize standardSize: CGFloat) -> MFSizeObject { + let object = MFSizeObject() + object.standardSize = standardSize + object.scaleStandardSize = true + return object + } + + /// Provide additional size information to help calculate its intrinsic height. + /// - Returns: The available spacing that can be used for intrinsic content width. + open class func maxAvailableLayoutWidth(size: CGFloat) -> CGFloat { + // The 2 is the product of both sides of padding. + size - (defaultHorizontalPadding(for: size) * 2) } //--------------------------------------------------