diff --git a/VDS/Fonts/Font.swift b/VDS/Fonts/Font.swift index 6b875ad3..f4ba798d 100644 --- a/VDS/Fonts/Font.swift +++ b/VDS/Fonts/Font.swift @@ -6,6 +6,7 @@ // import Foundation +import UIKit /// Enum that is matched up for the Verizon fonts. public enum Font: FontProtocol { @@ -14,7 +15,7 @@ public enum Font: FontProtocol { case dsLight case etxBold case etxRegular - case custom(String) + case custom(UIFont) public var fontName: String { switch self { @@ -28,8 +29,8 @@ public enum Font: FontProtocol { return "VerizonNHGeTX-Bold" case .etxRegular: return "VerizonNHGeTX-Regular" - case .custom(let fontName): - return fontName + case .custom(let font): + return font.fontName } } @@ -41,4 +42,19 @@ public enum Font: FontProtocol { public var fontFileExtension: String { return "otf" } + + /// Returns a UIFont for the fontName and size given. + /// - Parameters: + /// - size: Size of the font + /// - Returns: UIFont for the fontName and Size. + public func font(ofSize size: CGFloat) -> UIFont{ + DispatchQueue.once(block: { self.register() }) + switch self { + case .custom(let font): + return font + default: + guard let found = UIFont(name: self.fontName, size: size) else { return .systemFont(ofSize: size) } + return found + } + } } diff --git a/VDS/Fonts/FontProtocol.swift b/VDS/Fonts/FontProtocol.swift index fbca693b..df6ac6a3 100644 --- a/VDS/Fonts/FontProtocol.swift +++ b/VDS/Fonts/FontProtocol.swift @@ -9,7 +9,7 @@ import Foundation import UIKit /// Used in Classes that require Fonts -public protocol FontProtocol: Hashable { +public protocol FontProtocol { var fontFileExtension: String { get } var fontName: String { get } static var allCases: [Self] { get }