updated to handle custom fonts
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
fbdcdfc277
commit
fd641a85cf
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user