From 23f3f8b6bfe471b29ed8110785911f4e5ae4ae57 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 8 Mar 2024 10:08:50 -0600 Subject: [PATCH] added a conversion of a UIFont to a TextStyle Signed-off-by: Matt Bruce --- VDS/Typography/Typogprahy+Styles.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/VDS/Typography/Typogprahy+Styles.swift b/VDS/Typography/Typogprahy+Styles.swift index ec144617..0cd6e614 100644 --- a/VDS/Typography/Typogprahy+Styles.swift +++ b/VDS/Typography/Typogprahy+Styles.swift @@ -209,6 +209,24 @@ extension TextStyle { boldMicro ] } + + public static func convert(font: UIFont) -> TextStyle { + var found: TextStyle? + + for textStyle in allCases { + if font.fontName == textStyle.fontFace.fontName && + font.pointSize == textStyle.pointSize { + found = textStyle + break + } + } + + guard let found else { + return TextStyle(rawValue: "Custom", fontFace: .custom(font.fontName), pointSize: font.pointSize) + } + + return found + } } extension TextStyle {