How to use custom font in SwiftUI
Issue #586
In macOS
Add fonts to target. In Info.plist
, just need to specify font locations, most of the time they are at Resources folder
ATSApplicationFontsPath (String - macOS) identifies the location of a font file or directory of fonts in the bundle’s Resources directory. If present, macOS activates the fonts at the specified path for use by the bundled app. The fonts are activated only for the bundled app and not for the system as a whole. The path itself should be specified as a relative directory of the bundle’s Resources directory. For example, if a directory of fonts was at the path /Applications/MyApp.app/Contents/Resources/Stuff/MyFonts/, you should specify the string Stuff/MyFonts/ for the value of this key.
1 | <key>ATSApplicationFontsPath</key> |
Define font weight as enums, and base on ContentSizeCategory
1 | enum OpenSans: String { |
Then we can specify font weight, thanks to function overloading
1 | Text("Welcome") |
In iOS
Observe @Environment(\.sizeCategory) var sizeCategory
in ViewModifier