[英]Not able to load a custom font into an OSX project but… am into an iOS project?
I am able to load a custom font in an iOS project and see it on the available fonts using: 我能够在iOS项目中加载自定义字体,并使用以下命令在可用字体上查看它:
NSArray *fontFamilies = [UIFont familyNames];
for (int i=0; i<[fontFamilies count]; i++)
{
NSLog(@"Font: %@ ...", [fontFamilies objectAtIndex:i]);
}
But when I try and load the font into the OSX project, I am not able to see it in the list when I display the fonts: 但是,当我尝试将字体加载到OSX项目中时,在显示字体时我无法在列表中看到它:
NSLog(@"%@",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);
I used: Unable to set custom font for the UILabel in XCode to install the font for iOS project and assumed it should be the same approach for the OSX project. 我曾经使用过: 无法在XCode中为UILabel设置自定义字体来为iOS项目安装字体,并假定它对于OSX项目应该是相同的方法。
The link to the font file is in the bundle resources, Info.plist file(add: Fonts provided by application), and the file is in the Supporting files. 字体文件的链接位于包资源,Info.plist文件(添加:应用程序提供的字体)中,并且该文件位于支持文件中。
Am I missing something? 我想念什么吗? thx
谢谢
I solved it programmatically(but would prefer the approach like iOS approach in the link above): 我以编程方式解决了问题(但更喜欢上面链接中的iOS方法):
NSString* path = [[NSBundle mainBundle] pathForResource:@"Symbola" ofType:@"ttf"];
NSURL* fontsURL = [NSURL fileURLWithPath:path];
FSRef fsRef;
CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, kATSFontFormatUnspecified,
NULL, kATSOptionFlagsDefault, NULL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.