问题描述
我想在我的ios应用程序中使用HelveticaNeue-UltraLight。我将字体文件作为资源添加到我的项目中,并在plist文件中添加由应用程序提供的字体键。文件名是HelveticaNeue.dfont,我已将它添加到密钥数组。
I want to use HelveticaNeue-UltraLight in my ios application. I'm adding the font file as a resource to my project and adding the "Fonts provided by application" key in the plist file. The file name is HelveticaNeue.dfont and I've added it to the key array.
当我检查可用字体时,我现在可以看到它......
When I check for the available fonts I can see it now...
NSArray *fonts = [UIFont fontNamesForFamilyName:@"Helvetica Neue"];
for(NSString *string in fonts){
NSLog(@"%@", string);
}
1-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-Bold
2011-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-CondensedBlack
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue-Medium
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-Light
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-CondensedBold
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-LightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLight // HERE IT IS!
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-BoldItalic
2011-07-08 17:32:57.870 myApp[5159:207] HelveticaNeue-Italic
但是当我尝试使用[UIFont fontWithName:@HelveticaNeue-UltraLight尺寸:12]时我得到它HelveticaNeue-Light ..
But when I try to get it with [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:12] I just get HelveticaNeue-Light..
我没有收到任何错误或警告。
请帮助!
I'm getting no errors or warnings.Help please!
推荐答案
不仅需要将文件添加到项目中,还需要将其添加到项目中也加入了目标。
Not only does the file needs to be added to the project, but it needs to be added to the target as well.
有时(如我的情况),当在Xcode中拖放.ttf文件时,不会检查添加到目标。这意味着该文件实际上在您的项目中可见,但它未嵌入到应用程序中。
Sometimes (as in my case), when drag and dropping the ".ttf" file in Xcode, the "add to target" is not checked. This means the file is actually visible in your project, but it is not embedded in the app.
确保它是:
- 点击项目名称(左侧窗格)
- 然后在目标(中间窗格)上
- 然后构建阶段(右窗格中的第三个选项卡)
- 然后复制捆绑资源
- Click on the project's name (left pane)
- Then on the target (middle pane)
- Then "Build Phases" (third tab on the right pane)
- Then "Copy Bundle Resources"
你应该看到该列表中的字体文件。
You should see the font file in that list.
这篇关于ios中的自定义字体不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!