问题描述
我已经添加了一个自定义的字体 - 一个我从网上下载的。它是TTF格式,可以用在我的Mac上的其他程序。 (成功添加到字体书,并在烟花中使用)。我已经添加到信息.plist的密钥,但字体似乎不工作。
p>当我NSLog字体是空的,所以我假设它没有找到它。
TTF是称伦敦__。TTF,但有一个名字作为伦敦字体。
我应该使用什么字体,并将其添加到info.plist中以便使用?
谢谢 b
$ b
应用程序字体资源路径= LONDON __。TTF
NSLog(@%@,[UIFont fontWithName:@London fontsize:22]);
和
NSLog(@%@,[UIFont fontWithName:@LONDON __。TTFsize:22]);
返回空。
尽管文件名为LONDON __。TTF的字体在Font Book中显示为所有人。是这个问题吗?
查看所有可用的字体
Objective-C:
$ b
for(NIFtring * family in [UIFont familyNames]){
NSLog(@%@,family);
for(NSString * name in [UIFont fontNamesForFamilyName:family]){
NSLog(@%@,name);
Swift
$ bfor family:UIFont.familyNames()中的字符串(
print(%@,family)
对于名称:UIFont.fontNamesForFamilyName(family)中的字符串{
print(%@,name)
}
}
..如果不存在,再次安装
$ b
- >在你的
.ttf
文件放到您的项目中(即将其拖到项目导航器中的资源文件夹中)。Info.plist
中添加一个带有数组类型的键由应用程序
提供的字体的条目。作为第0项,添加一个对应于字体文件名的字符串值(例如OpenSans-ExtraBoldItalic.ttf
)。
确保字体文件包含在项目设置下的
copy bundle resources
列表中。
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).
I have added the key to the info .plist but the font doesn't seem to work.
When i NSLog the font it is null so i am assuming it isn't finding it.
The TTF is called LONDON__.TTF but has a name as London font.
What should i use as the font and add to the info.plist for this to work?
Thanks
Dan
Application fonts resource path = LONDON__.TTF
NSLog(@"%@",[UIFont fontWithName:@"London font" size:22]);
and
NSLog(@"%@",[UIFont fontWithName:@"LONDON__.TTF" size:22]);
Both of them return Null.
Although the file is named LONDON__.TTF the font appear as everyone in Font Book. is this the issue?
解决方案Look at all the available fonts
Objective-C:
for(NSString* family in [UIFont familyNames]) { NSLog(@"%@", family); for(NSString* name in [UIFont fontNamesForFamilyName: family]) { NSLog(@" %@", name); } }
Swift:
for family: String in UIFont.familyNames() { print("%@", family) for name: String in UIFont.fontNamesForFamilyName(family) { print(" %@", name) } }
..if it's not there, install again
Copy the
.ttf
file into your project (i.e. drag it to the resource folder in the Project navigator).In your
Info.plist
add an entry with the keyFonts 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
).Make sure the font file is included in the
copy bundle resources
list under the project settings.
这篇关于不能找到自定义字体 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!