字体未在 XCode 中加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10170476/
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-14 23:59:05  来源:igfitidea点击:

Font not loading in XCode

iphoneobjective-cxcodefontsuifont

提问by sergiocg90

Well, I want to import a new Font to my application but without success. I have the Fonts provided by application key in my .plist , I have my font in the Item 0 as a String and the value AdelleBasic_Bold.otf, I have added that Font to my project, and I am trying to use it with:

好吧,我想将新字体导入我的应用程序,但没有成功。我的 .plist 中有应用程序密钥提供的字体,我在 Item 0 中有我的字体作为字符串和值 AdelleBasic_Bold.otf,我已将该字体添加到我的项目中,我正在尝试将其用于:

_myTextField.font = [UIFont fontWithName:@"Adelle Basic" size:15];

Adelle Basic is the header of the Font when I open it. I have also tried without any success:

Adelle Basic 是我打开字体时的标题。我也试过没有任何成功:

_myTextField.font = [UIFont fontWithName:@"AdelleBasic_Bold" size:15];

Any suggestion?

有什么建议吗?

回答by SomaMan

This may well not true for all fonts, but in my experience, Xcode can be fussy, & I've never been able to get it to use otf fonts (anyone who has please post!), so I've always converted my fonts using this really excellent website - Online Font Converter

这可能不适用于所有字体,但根据我的经验,Xcode 可能很繁琐,而且我从来没有让它使用 otf 字体(任何有请发帖的人!),所以我总是转换我的字体使用这个非常出色的网站 -在线字体转换器

I convert them to ttf fonts, and they always seem to work fine - make sure you use the exact name (changing the filename of the font seems to stop it working too).

我将它们转换为 ttf 字体,并且它们似乎总是可以正常工作 - 确保使用确切的名称(更改字体的文件名似乎也会停止工作)。

Hope this helps.

希望这可以帮助。

回答by i--

Below is the proper way to add fonts to your XCODE app (.otf fonts work fine):

以下是将字体添加到 XCODE 应用程序的正确方法(.otf 字体工作正常):

  1. Include your fonts in your XCode project
  2. Make sure that they're included in the target
  3. Double check that your fonts are included as Resources in your bundle
  4. Include your iOS custom fonts in your application plist
  5. Find the name of the font
  1. 在 XCode 项目中包含您的字体
  2. 确保它们包含在目标中
  3. 仔细检查您的字体是否作为资源包含在您的包中
  4. 在您的应用程序 plist 中包含您的 iOS 自定义字体
  5. 查找字体名称

Credits and better explaination with images here

学分和更好的解释与图像在这里

回答by Charan

you can use only the third party fonts which have extension as ttf and the fonts which have otf extension will not work effectively and mostly doesn't work

您只能使用具有 ttf 扩展名的第三方字体,而具有 otf 扩展名的字体将无法有效工作,并且大多数情况下不起作用

回答by Javier Calatrava Llavería

Apart from assuring the 5 points, you could also try out the following snippet of code that prints out the installed fonts:

除了确保 5 点之外,您还可以尝试以下代码片段来打印已安装的字体:

for (NSString* family in [UIFont familyNames])
{   
    NSLog(@"%@", family)       
    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"  %@", name);
    }
}

If the font that you want to use is not listed, then you missed in some of the 5 steps.

如果未列出您要使用的字体,则您错过了 5 个步骤中的某些步骤。

回答by WINSergey

I just add font into project, check if font will copy inside bundle. Set up it on my Mac and directly use font inside Interface Builder. If you will have any problems solve they here.

我只是将字体添加到项目中,检查字体是否会复制到包中。在我的 Mac 上设置它并直接在 Interface Builder 中使用字体。如果您有任何问题,请在此处解决