我已经看到这个问题多次回答,但我还没有看到真正的答案.
常见的“解决方案”是:
常见的“解决方案”是:
>将该字体添加到应用程序包中,并将其注册到info.plist文件中.
>使用自定义字体解析和渲染库(如Zynga的FontLabel).
>不能完成
所以问题是:如何在iOS下动态加载字体?
加载字体“动态”是指加载应用程序编译时未知的任何给定字体.
解决方法
字体可以轻松地从任何位置或任何字节流动态加载.参见文章:
http://www.marco.org/2012/12/21/ios-dynamic-font-loading
NSData *inData = /* your font-file data */;
CFErrorRef error;
CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
CGFontRef font = CGFontCreateWithDataProvider(provider);
if (! CTFontManagerRegistergraphicsFont(font,&error)) {
CFStringRef errorDescription = CFErrorcopyDescription(error)
NSLog(@"Failed to load font: %@",errorDescription);
CFRelease(errorDescription);
}
CFRelease(font);
CFRelease(provider);
>你不必把字体放在你的包中.
>您不必在info.plist中明确注册该字体.
也可以看看:
https://developer.apple.com/library/mac/#documentation/Carbon/Reference/CoreText_FontManager_Ref/Reference/reference.html#//apple_ref/doc/uid/TP40008278
https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGFont/Reference/reference.html#//apple_ref/c/func/CGFontCreateWithDataProvider