forked from RedMadRobot/figma-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIFont+extension.swift
48 lines (39 loc) · 1.35 KB
/
UIFont+extension.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// The code generated using FigmaExport — Command line utility to export
// colors, typography, icons and images from Figma to Xcode project.
//
// https://github.com/RedMadRobot/figma-export
//
// Don’t edit this code manually to avoid runtime crashes
//
import UIKit
public extension UIFont {
static func largeTitle() -> UIFont {
customFont("PTSans-Bold", size: 34.0, textStyle: .largeTitle, scaled: true)
}
static func header() -> UIFont {
customFont("PTSans-Bold", size: 20.0)
}
static func body() -> UIFont {
customFont("PTSans-Regular", size: 16.0, textStyle: .body, scaled: true)
}
static func caption() -> UIFont {
customFont("PTSans-Regular", size: 14.0, textStyle: .footnote, scaled: true)
}
private static func customFont(
_ name: String,
size: CGFloat,
textStyle: UIFont.TextStyle? = nil,
scaled: Bool = false) -> UIFont {
guard let font = UIFont(name: name, size: size) else {
print("Warning: Font \(name) not found.")
return UIFont.systemFont(ofSize: size, weight: .regular)
}
if scaled, let textStyle = textStyle {
let metrics = UIFontMetrics(forTextStyle: textStyle)
return metrics.scaledFont(for: font)
} else {
return font
}
}
}