如何确保iOS应用程序的自定义字体能够显示?

huangapple go评论85阅读模式
英文:

What else to check so that iOS app custom fonts will appear?

问题

I am using Xcode 14.2 and building a SwiftUI application with 4 custom fonts. The fonts were previously loaded and usable in previews, but they are now oddly missing.

以下是要翻译的内容:

  1. The fonts are listed as references in the file navigator. I have removed and re-added them.
    字体在文件导航器中列为引用。我已将它们移除并重新添加。

  2. For each font file, TargetMembership is checked / true for the only target in the app.
    对于每个字体文件,已检查目标成员资格,对于应用程序中唯一的目标,其值为真。

  3. The target's "Info" tab contains "Fonts provided by the application" with all 4 fonts listed as array elements and their filenames spelled correctly.
    目标的“信息”选项卡包含“应用程序提供的字体”,其中包括所有4种字体,其文件名拼写正确。

  4. The target's Build Phases tab / Copy bundle resources lists all 4 fonts -- in addition to a couple images that are appearing correctly.
    目标的“构建阶段”选项卡/复制包资源列出了所有4种字体,以及一些正确显示的图像。

  5. The entitlements file includes "Use fonts" and "Install fonts".
    权限文件包括“使用字体”和“安装字体”。

  6. Code that was correctly working earlier has not been changed; it is using the correct font names.
    先前正确工作的代码未更改;它正在使用正确的字体名称。

  7. The following code does NOT list the custom fonts:

      .onAppear(){
        for family: String in UIFont.familyNames
        {
          print(family)
          for name: String in
                UIFont.fontNames(forFamilyName: family)
          {
            print("== \(name)")
          }
        }
      }

以下代码未列出自定义字体:

      .onAppear(){
        for family: String in UIFont.familyNames
        {
          print(family)
          for name: String in
                UIFont.fontNames(forFamilyName: family)
          {
            print("== \(name)")
          }
        }
      }
  1. I have tried to view the build output but I cannot determine for sure what's in or out - everything's either bundled into the 14 GB(!) executable or in a .car database.
    我尝试查看构建输出,但无法确定其中包含或排除了什么 - 所有内容都要么捆绑到了14 GB的可执行文件中,要么在.car数据库中。

我可以帮助您进一步解决问题吗?

英文:

I am using Xcode 14.2 and building a SwiftUI application with 4 custom fonts. The fonts were previously loaded and usable in previews, but they are now oddly missing.

The following things are true:

  1. The fonts are listed as references in the file navigator. I have removed and re-added them.
  2. For each font file, TargetMembership is checked / true for the only target in the app
  3. The target's "Info" tab contains "Fonts provided by the application" with all 4 fonts listed as array elements and their filenames spelled correctly
  4. The target's Build Phases tab / Copy bundle resources lists all 4 fonts -- in addition to a couple images that are appearing correctly
  5. The entitlements file includes "Use fonts" and "Install fonts"
  6. Code that was correctly working earlier has not been changed; it is using the correct font names
  7. The following code does NOT list the custom fonts:
      .onAppear(){
        for family: String in UIFont.familyNames
        {
          print(family)
          for name: String in
                UIFont.fontNames(forFamilyName: family)
          {
            print("== \(name)")
          }
        }
  1. I have tried to view the build output but I cannot determine for sure what's in or out - everything's either bundled into the 14 GB(!) executable or in a .car database.

What else can I do to fix this? How can I keep from having to re-address this every couple weeks?

答案1

得分: 0

以下是翻译好的部分:

所以,我问了ChatGPT。它的第一个建议是这样的:

<pre>
清理并重新构建项目:有时候Xcode可能会出现缓存问题。尝试通过选择
Xcode菜单中的“产品”,然后选择“清理构建文件夹”来清理项目。清理后,通过选择“产品”,然后选择“构建”来重新构建项目。
</pre>

哈!太棒了 - 三指敬礼!这是Win95吗?

<ol>
<li>我退出了Xcode
<li>删除了~/Library/Developer/Xcode/DerivedData中的所有内容
<li>重新启动了Xcode
<li>打开了项目并进行了构建
<li>出现了缺少Info.plist的构建错误,检查了目标的Info选项卡,发现Fonts键丢失(如上所述,以前是存在的!
<li>添加了“应用程序提供的字体”键
<li>发现我的Fonts/组中有一个文件有问题(如上所述,以前是正确的),所以我删除了并添加了正确的引用
<li>将每个字体文件名添加到Info.plist的“应用程序提供的字体...”数组中
<li>重新构建
<li>打开了一个视图并取消了预览暂停
</ol>

字体出现了!!太好了!

哇,这就是2天的强迫症麻烦,全都解决了。以前NeXT的时候从来不会发生这种事...

英文:

So, I asked ChatGPT. It's first suggestion was this:

<pre>
Clean and rebuild the project: Sometimes Xcode can have
caching issues. Try cleaning your project by selecting
"Product" from the Xcode menu, then choose "Clean Build
Folder." After cleaning, rebuild your project by selecting
"Product" and then "Build."
</pre>

Ha! Great - the three-fingered solute! What is this Win95?

<ol>
<li>I quit Xcode
<li>removed everything in ~/Library/Developer/Xcode/DerivedData
<li>Restarted Xcode
<li>Opened the project and built
<li>Got a build error with missing Info.plist and checked the target's Info tab and saw the Fonts key was missing (<b>as noted above, it was previously there!</b>)
<li>Added the Fonts provided by the application key
<li>Saw that my Fonts/ group had the wrong file for one of the files (<b>as noted above, this was previously correct</b>) so I deleted and added the correct reference
<li>Added each of the font filenames into the Info.plist "Fonts provided..." array
<li>Rebuilt
<li>Opened a view and unpaused the preview
</ol>

The fonts appeared!! Yay!

Wow, that's 2 days of OCD hassle just lost. This never wouldda happened when they were NeXT...

huangapple
  • 本文由 发表于 2023年5月25日 03:46:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326933.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定