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/, you should specify the string Stuff/MyFonts/ for the value of this key.


Define font weight as enums, and base on ContentSizeCategory

enum OpenSans: String {
    case bold = "OpenSans-Bold"
    case semiBold = "OpenSans-SemiBold"
    case extraBold = "OpenSans-ExtraBold"
    case light = "OpenSans-Light"
    case regular = "OpenSans-Regular"

enum FiraCode: String {
    case bold = "FiraCode-Bold"
    case medium = "FiraCode-Medium"
    case light = "FiraCode-Light"
    case regular = "FiraCode-Regular"
    case retina = "FiraCode-Retina"

extension ContentSizeCategory {
    var size: CGFloat {
        switch self {
        case .small:
            return 14
        case .medium:
            return 16
        case .large:
            return 20
            return 14

extension View {
    func customFont(_ font: OpenSans, category: ContentSizeCategory) -> some View {
        return self.customFont(font.rawValue, category: category)

    func customFont(_ name: String, category: ContentSizeCategory) -> some View {
        return self.font(.custom(name, size: category.size))

Then we can specify font weight, thanks to function overloading

    .customFont(OpenSans.bold, category: .large)

In iOS

Observe @Environment(\.sizeCategory) var sizeCategory in ViewModifier

Read more