【发布时间】:2012-03-01 14:52:04
【问题描述】:
我想为UILabel 使用自定义字体。自定义字体由文件加载:
NSString *fontPath = ... ; // a TTF file in iPhone Documents folder
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]);
CGFontRef customFont = CGFontCreateWithDataProvider(fontDataProvider);
CGDataProviderRelease(fontDataProvider);
如何将CGFontRef 转换为UIFont 以在[UILabel setFont:] 中使用?
【问题讨论】:
-
您需要支持什么iOS版本?您可以通过编辑 Info.plist 将捆绑的字体加载为
UIFont实例。 -
我不确定将 CGFontRef 转换为 UIFont,但您可以创建一个采用 CGFontRef 的 UILabel 子类。检查此blog 进行操作
-
@Costique iOS 4.3 或更高版本是可以的。字体是用户下载应用后添加的,所以无法预设Info.plist。