找不到自定义字体 - iOS [英] Cant find custom font - iOS

查看:36
本文介绍了找不到自定义字体 - iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一种自定义字体 - 我从网上下载的一种.它是 TTF 格式,可以在我的 mac 上的其他程序上使用.(成功添加到字体册并用于烟花).

i have added a custom font - one which i have downloaded from from the net. it is in TTF format and can be used on other programs on my mac. (Successfully added it to font book and used in fireworks).

我已将密钥添加到信息 .plist 中,但字体似乎不起作用.

I have added the key to the info .plist but the font doesn't seem to work.

当我 NSLog 字体时,它为空,所以我假设它没有找到它.

When i NSLog the font it is null so i am assuming it isn't finding it.

TTF 称为 LONDON__.TTF,但名称为 London 字体.

The TTF is called LONDON__.TTF but has a name as London font.

我应该使用什么作为字体并将其添加到 info.plist 以使其正常工作?

What should i use as the font and add to the info.plist for this to work?

谢谢

应用字体资源路径 = LONDON__.TTF

Application fonts resource path = LONDON__.TTF

NSLog(@"%@",[UIFont fontWithName:@"London font" size:22]);

NSLog(@"%@",[UIFont fontWithName:@"LONDON__.TTF" size:22]);

它们都返回 Null.

Both of them return Null.

虽然文件名为 LONDON__.TTF,但字体在字体簿中显示为每个人.这是问题吗?

Although the file is named LONDON__.TTF the font appear as everyone in Font Book. is this the issue?

推荐答案

查看所有可用的字体

目标 C:

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

斯威夫特:

for family: String in UIFont.familyNames() {
    print("%@", family)
    for name: String in UIFont.fontNamesForFamilyName(family) {
        print("  %@", name)
    }
}

...如果没有,请重新安装

  1. .ttf 文件复制到您的项目中(即将它拖到项目导航器中的资源文件夹中).

  1. Copy the .ttf file into your project (i.e. drag it to the resource folder in the Project navigator).

在您的 Info.plist 中添加一个条目,其键为 应用程序提供的字体,类型为 Array.作为 Item 0,添加与字体文件名对应的 String 值(例如 OpenSans-ExtraBoldItalic.ttf).

In your Info.plist add an entry with the key Fonts provided by application with an Array type. As Item 0, add a String value corresponding to the font file name (e.g. OpenSans-ExtraBoldItalic.ttf).

确保字体文件包含在项目设置下的copy bundle resources列表中.

Make sure the font file is included in the copy bundle resources list under the project settings.

这篇关于找不到自定义字体 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆