the*_*end 41 iphone cocoa-touch uifont custom-font ios
我想在我的ios应用程序中使用HelveticaNeue-UltraLight.我将字体文件作为资源添加到我的项目中,并在plist文件中添加"由应用程序提供的字体"键.文件名是HelveticaNeue.dfont,我已将其添加到密钥数组中.
当我检查可用字体时,我现在可以看到它...
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
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用[UIFont fontWithName:@"HelveticaNeue-UltraLight"尺寸:12]时,我只是得到了HelveticaNeue-Light ..
我没有收到任何错误或警告.请帮忙!
Ben*_*n G 99
不仅需要将文件添加到项目中,还需要将其添加到目标中.
有时(如我的情况),当在Xcode中拖放".ttf"文件时,不会检查"添加到目标".这意味着该文件实际上在您的项目中可见,但它未嵌入应用程序中.
确保它是:
您应该在该列表中看到该字体文件.
Thi*_*tte 19
我认为你遇到了同样的问题:iOS中存在一个错误,它无法使用同一系列中超过2种字体.
有关详细信息和解决方案,请参阅博客文章:http://www.pixeldock.com/blog/uifont-problem-when-using-more-than-2-custom-fonts-of-the-same-font-family/
它使用相同字体的不同变体(即使在IOS 8中).我会发布我的错误以防有人遇到同样的问题...我使用的是字体文件名而不是字体名称.一个有用的解决方案是打印所有可用的字体并查找我正在使用的字体.在Swift中会是:
for fontFamilyNames in UIFont.familyNames {
for fontName in UIFont.fontNames(forFamilyName: fontFamilyNames) {
print("FONTNAME:\(fontName)")
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了这个有用的教程:与Chris的代码