Xcode 自定义字体未显示在 Storyboard 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32755428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:55:49  来源:igfitidea点击:

Xcode custom fonts not showing up in Storyboard

iosxcodefonts

提问by Lord Vermillion

I added my two fonts to my project folder:

我将两种字体添加到我的项目文件夹中:

enter image description here

在此处输入图片说明

I added them to info.plist:

我将它们添加到 info.plist:

enter image description here

在此处输入图片说明

I can not see them in my custom font list in the storyboard:

我在故事板的自定义字体列表中看不到它们:

enter image description here

在此处输入图片说明

What have i done wrong?

我做错了什么?

回答by DS.

I know this is a pretty old question, but I ran into the same issue. And the above tips didn't work for me. Apart from the standard checks (present in bundle, restarting XCode, the thing that fixed my issue was that my label text type was marked as "Plain" and hence some fonts were not showing in the dropdown in the Storyboard. As soon as I changed the text type to "Attributed", all the fonts appeared in the dropdown.

我知道这是一个很老的问题,但我遇到了同样的问题。以上提示对我不起作用。除了标准检查(存在于捆绑包中,重新启动 XCode,解决我的问题的是我的标签文本类型被标记为“普通”,因此一些字体没有显示在故事板的下拉列表中。一旦我改变了文本类型为“属性”,所有字体都出现在下拉列表中。

Hope this'll help someone stuck with the same issue.

希望这能帮助遇到同样问题的人。

回答by DarkDust

This drop-down box shows the system-wide installed fonts. So you need to install your custom font on your system first so it's appearing in that drop-down box. You can do that by double-clicking it, the FontBook.app opens and asks you whether you want to install the font.

此下拉框显示系统范围内安装的字体。所以你需要先在你的系统上安装你的自定义字体,这样它才会出现在那个下拉框中。您可以通过双击它来执行此操作,FontBook.app 将打开并询问您是否要安装该字体。

回答by R. Mohan

I Installed the font in the system as per DarkDust solution and i am able to see the font in attributed type.

我按照 DarkDust 解决方案在系统中安装了字体,我能够看到属性类型的字体。

Then i changed the type to plain and i able to see the Custom font in the font types drop down.

然后我将类型更改为普通字体,我可以在字体类型下拉列表中看到自定义字体。

回答by Sean Dev

Had the same problem but this SO answer by user Saranjith solved it while the other solutions in this thread didn't: Xcode 8 custom font doesn't show up in interface builder

有同样的问题,但用户 Saranjith 的这个 SO 回答解决了它,而这个线程中的其他解决方案没有:Xcode 8 自定义字体没有出现在界面构建器中

Basically in Font Book select "Computer Fonts" and then hit the + button and re add the Fonts.

基本上在字体簿中选择“计算机字体”,然后点击 + 按钮并重新添加字体。

This is happened to me after moving to Xcode 11 in Catalina from Xcode 10 in Mojave.

从 Mojave 中的 Xcode 10 移动到 Catalina 中的 Xcode 11 后,这发生在我身上。

回答by Jordan Kinsley

This was a huge headache for me but I simply fixed it by: I fixed the issue by restarting my Mac. Then restarting Xcode.

这对我来说是一个巨大的头痛,但我只是通过以下方式解决了它:我通过重新启动我的 Mac 解决了这个问题。然后重新启动Xcode。

回答by Ryan H

Well, silly mistake on my part, but I didn't realize my font was named something way different from the file name.

好吧,我犯了一个愚蠢的错误,但我没有意识到我的字体命名方式与文件名不同。

Double-clicking the actual font file opened it in the font book, and that showed the actual font name. It was in the dropdown all along.

双击实际字体文件在字体簿中打开它,并显示实际字体名称。它一直在下拉列表中。

回答by Luat Vu Dinh

Sometime I go to another file and come back, then my custom fonts are arrived. I think this is an issue of Xcode and will be solved in following version.

有时我去另一个文件然后回来,然后我的自定义字体就到了。我认为这是 Xcode 的问题,将在以下版本中解决。

回答by ethemsulan

I solved my problem when i used font name. Do not use file name. I was used like this [UIFont fontWithName:@"appFont" size:17] but it is wrong.

当我使用字体名称时,我解决了我的问题。不要使用文件名。我是这样使用的 [UIFont fontWithName:@"appFont" size:17] 但它是错误的。

  1. Upload your font file to https://fontdrop.info/and use the name
  2. My font file name is appFont.ttf but when i uploaded i saw Roboto Regular.
  3. [UIFont fontWithName:@"Roboto Regular" size:17]
  1. 将您的字体文件上传到https://fontdrop.info/并使用名称
  2. 我的字体文件名是 appFont.ttf 但是当我上传时我看到了 Roboto Regular。
  3. [UIFont fontWithName:@"Roboto Regular" size:17]

回答by Serega

If Xcode showed your custom font before but stopped to do it at some moment, try to readd font files to your project. It solved the problem for me. Other answers weren't helpful.

如果 Xcode 之前显示过您的自定义字体但在某个时候停止显示,请尝试将字体文件读取到您的项目中。它为我解决了这个问题。其他答案没有帮助。