commented on Fonts
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e02d4ed83f
commit
48411cb7c3
@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Enum that is matched up for the Verizon fonts.
|
||||
public enum Font: String, FontProtocol {
|
||||
case dsBold
|
||||
case dsRegular
|
||||
@ -29,6 +30,7 @@ public enum Font: String, FontProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/// File Extension for each of the Font enums.
|
||||
public var fontFileExtension: String {
|
||||
return "otf"
|
||||
}
|
||||
|
||||
@ -8,12 +8,15 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
/// Used in Classes that require Fonts
|
||||
public protocol FontProtocol: CaseIterable, RawRepresentable, Hashable {
|
||||
var fontFileExtension: String { get }
|
||||
var fontName: String { get }
|
||||
}
|
||||
|
||||
extension FontProtocol {
|
||||
|
||||
/// Registers the fonts used in the VDS Framework.
|
||||
public func register() {
|
||||
guard let bundle = Bundle(identifier: "com.vzw.vds") else { return }
|
||||
Self.allCases.forEach{ font in
|
||||
@ -29,6 +32,8 @@ extension FontProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers a font from a fileLocation
|
||||
/// - Parameter url: URL of the file location.
|
||||
public static func register(from url: URL) throws {
|
||||
guard let fontDataProvider = CGDataProvider(url: url as CFURL) else {
|
||||
throw NSError(domain: "www.verizon.com", code: 123, userInfo: ["description":"Could not create font data provider for \(url)."])
|
||||
@ -40,7 +45,11 @@ extension FontProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public func font(ofSize size: CGFloat, isScaled: Bool = true) -> UIFont{
|
||||
/// 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() })
|
||||
guard let found = UIFont(name: self.fontName, size: size) else { return .systemFont(ofSize: size) }
|
||||
return found
|
||||
|
||||
Loading…
Reference in New Issue
Block a user