-
Notifications
You must be signed in to change notification settings - Fork 2
/
Fonts.swift
51 lines (37 loc) · 1.1 KB
/
Fonts.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
import SwiftUI
enum CustomFontType: String {
case regular = "OpenSans-Regular"
case semiBold = "OpenSans-SemiBold"
case bold = "OpenSans-Bold"
case light = "OpenSans-Light"
}
// MARK: - SwiftUI
extension Font {
static func customFont(type: CustomFontType, size: CGFloat) -> Font {
return custom(type.rawValue, size: size)
}
static let titleFont: Font = {
return customFont(type: .semiBold, size: 26)
}()
static let descriptionFont: Font = {
return customFont(type: .semiBold, size: 14)
}()
}
struct ContentView: View {
var body: some View {
Text("Hello World!")
.font(.titleFont)
}
}
// MARK: - UIKit
extension UIFont {
static func customFont(type: CustomFontType, size: CGFloat) -> UIFont {
return UIFont(name: type.rawValue, size: size) ?? UIFont.systemFont(ofSize: size)
}
static let titleFont: UIFont = {
return customFont(type: .semiBold, size: 26)
}()
static let descriptionFont: UIFont = {
return customFont(type: .semiBold, size: 14)
}()
}