updated to handle custom fonts

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-08 12:34:31 -06:00
parent fbdcdfc277
commit fd641a85cf
2 changed files with 20 additions and 4 deletions

View File

@ -6,6 +6,7 @@
// //
import Foundation import Foundation
import UIKit
/// Enum that is matched up for the Verizon fonts. /// Enum that is matched up for the Verizon fonts.
public enum Font: FontProtocol { public enum Font: FontProtocol {
@ -14,7 +15,7 @@ public enum Font: FontProtocol {
case dsLight case dsLight
case etxBold case etxBold
case etxRegular case etxRegular
case custom(String) case custom(UIFont)
public var fontName: String { public var fontName: String {
switch self { switch self {
@ -28,8 +29,8 @@ public enum Font: FontProtocol {
return "VerizonNHGeTX-Bold" return "VerizonNHGeTX-Bold"
case .etxRegular: case .etxRegular:
return "VerizonNHGeTX-Regular" return "VerizonNHGeTX-Regular"
case .custom(let fontName): case .custom(let font):
return fontName return font.fontName
} }
} }
@ -41,4 +42,19 @@ public enum Font: FontProtocol {
public var fontFileExtension: String { public var fontFileExtension: String {
return "otf" 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
}
}
} }

View File

@ -9,7 +9,7 @@ import Foundation
import UIKit import UIKit
/// Used in Classes that require Fonts /// Used in Classes that require Fonts
public protocol FontProtocol: Hashable { public protocol FontProtocol {
var fontFileExtension: String { get } var fontFileExtension: String { get }
var fontName: String { get } var fontName: String { get }
static var allCases: [Self] { get } static var allCases: [Self] { get }