自定义字体未显示在 SwiftUI 中

Zor*_*gan 1 xcode ios swift swiftui

我已按照 Apple 教程中的所有步骤添加自定义字体

我已将字体文件添加到名为的文件夹下fonts

在此输入图像描述

我已通过将字体添加到以下位置来注册字体Info.plist

在此输入图像描述

然而 Xcode 无法使用它们/找到它们:

Button(action: {}){
                Text("View profile")
                    .font(Font.custom("seravekBold.tff", size: 20.0))
Run Code Online (Sandbox Code Playgroud)

我也尝试过测试这个方法:

for family in UIFont.familyNames.sorted() {
    let names = UIFont.fontNames(forFamilyName: family)
    print("Family: \(family) Font names: \(names)")
}
Run Code Online (Sandbox Code Playgroud)

在 my 中AppDelegate打印所有 UI 字体,但我添加的字体 ( seravek) 不显示。

知道问题是什么吗?

Asp*_*eri 6

这是我的步骤(使用 Xcode 12 / iOS 14 准备和测试演示):

  1. 从http://fdempreendimentos.com.br/assets/fonts/Seravek-Bold.ttf获取演示字体

  2. 拖放到项目中并标记复选框以包含到应用程序目标

演示

  1. 使用 Info.plist 注册字体

演示2

  1. 演示内容视图
struct TestSeravekFont: View {
    var body: some View {
        Text("Hello, World! Specific Qij")
            .font(Font.custom("Seravek Bold", size: 40))
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 输出

演示3

这是字体在字体管理器中的外观,所以我们看到就是这样。完毕。

演示4