forked from RedMadRobot/figma-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIFont+extension.swift
52 lines (42 loc) · 1.44 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
49
50
51
52
//
// 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 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)
}
static func header() -> UIFont {
customFont("PTSans-Bold", size: 20.0)
}
static func largeTitle() -> UIFont {
customFont("PTSans-Bold", size: 34.0, textStyle: .largeTitle, scaled: true)
}
static func uppercased() -> UIFont {
customFont("PTSans-Regular", size: 14.0)
}
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
}
}
}