本文介绍了在iOS应用程序中使用字体(ttf或odf) - 它们是否正常工作? (SourceSansPro-ExtraLight)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我按照以下步骤操作:


  1. 将字体拖放到我的项目中并复制到项目中

  2. 确保字体包含在构建阶段中
  3. >
  4. 将字体名称(包括扩展名)添加到应用程序的plist文件中。我确认我使用的是后缀名称:SourceSansPro-ExtraLight.ttf 尝试使用字体

    自我.daysLeftLabel.font = [UIFont fontWithName:@SourceSansPro-ExtraLightsize:14];


使用通用系统字体。



如果我在代码中运行这个代码示例:

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


$ / code>

Source Sans Pro字体家族不包括在内这个,所以有些东西是不行的。

事情是,我遵循了其他自定义TTF字体完全相同的序列,他们按预期工作。据我所知,我做的一切都是正确的 - 包括plist文件中经常错过的postscript名字和扩展名。



所以,我开始怀疑一些TTF字体是否与iOS兼容,而另一些则不是。是这样的吗?

解决方案

我也有同样的问题,您必须在info.plist文件中添加实际的文件名,而不是字体名称。在UILabel中定义字体时,您必须使用真实的字体名称。


I've had hit-or-miss success with using custom fonts in an iOS app.

I follow these steps:

  1. Drag in the font into my project and copy into the project
  2. Make sure the font is included in the Build Phases
  3. Add the font name (including the extension) into the app's plist file. I confirmed that I am using the postscript name: SourceSansPro-ExtraLight.ttf
  4. Try to use the font

    self.daysLeftLabel.font = [UIFont fontWithName:@"SourceSansPro-ExtraLight" size:14];

However, only the generic system font is used.

If I run this code sample in my code:

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

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

The Source Sans Pro font family isn't included in this, so something isn't working.

The thing is, I followed the exact same sequence for other custom TTF fonts and they work as expected. As far as I can tell, I am doing everything right -- including the often-missed postscript name in the plist file along with the extension.

So, I'm beginning to wonder if some TTF fonts are compatible with iOS and some others aren't. Is this the case?

解决方案

I have the same issue too, you have to add actual filename in info.plist file instead of font name. while defining font in UILabel you have to use true font name.

这篇关于在iOS应用程序中使用字体(ttf或odf) - 它们是否正常工作? (SourceSansPro-ExtraLight)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 21:01