gpt4 book ai didi

ios - 自定义字体未在 SwiftUI 中显示

转载 作者:行者123 更新时间:2023-12-01 19:31:43 25 4
gpt4 key购买 nike

我已按照 Apple's tutorial to add custom fonts 中的所有步骤进行操作:

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

enter image description here

我已经通过将它们添加到 Info.plist 来注册字体:

enter image description here

但是 Xcode 不能使用它们/找到它们:

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

我也试过测试这种方法:
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}

在我的 AppDelegate打印出所有 UI 字体,并且我添加的字体 ( seravek) 不显示。

知道问题是什么吗?

最佳答案

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

  • http://fdempreendimentos.com.br/assets/fonts/Seravek-Bold.ttf 获取演示字体
  • 拖放到项目和标记复选框以包含到应用程序目标

  • demo
  • 使用 Info.plist
  • 注册字体

    demo2
  • 演示内容查看
  • struct TestSeravekFont: View {
    var body: some View {
    Text("Hello, World! Specific Qij")
    .font(Font.custom("Seravek Bold", size: 40))
    }
    }
  • 输出

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

    关于ios - 自定义字体未在 SwiftUI 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62447128/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com