【问题标题】:SF Pro Display Font not working in SwiftUI ViewSF Pro 显示字体在 SwiftUI 视图中不起作用
【发布时间】:2021-07-02 06:58:48
【问题描述】:

一直在尝试在SwiftUI 中实现SF Pro Display 字体,但没有成功!我已经在 Xcode 和 info.plist 文件中复制了这些文件。其他字体工作但SF Pro Display 不工作。有人可以帮忙吗?

[UPDATE: No need to import SF Fonts in Xcode. Xcode uses SF Pro Display Fonts by default]

扩展名:

extension Font {

struct SF {
    static func regular(size: CGFloat) -> Font {
        .custom("SF-Pro-Display-Regular", size: size)
    }
    
    static func light(size: CGFloat) -> Font {
        .custom("SF-Pro-Display-Light", size: size)
    }
    
    static func medium(size: CGFloat) -> Font {
        .custom("SF-Pro-Display-Medium", size: size)
    }
}

在 SwiftUI 中

Text("81%")
  .font(Font.SF.medium(size: 55))
  .shadow(radius: 10, y: 5)

Info.plist

Fonts in Xcode

SwiftUI Preview

【问题讨论】:

    标签: ios swift xcode fonts swiftui


    【解决方案1】:

    我有同样的问题,我很久以前在某个地方发现它需要您可以在 Font Book 中找到的“PostScript 名称”,据我从文档中了解到,您不需要将其导入 .列表。

    font book

    【讨论】:

    • 只能暂时工作。 Apple 不鼓励这样做,并为此目的制作了 Font.system API。
    猜你喜欢
    • 2016-05-24
    • 2019-10-26
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    相关资源
    最近更新 更多