iOS-动态下载中文字体
2016-12-20 本文已影响359人
StrongX
从iOS6开始,苹果开始支持动态下载官方提供的中文字体到系统中。使用苹果官方提供的中文字体,既可以避免版权问题,又可以节省应用体积。该方案适合对字体有较多需求的应用。
——以上摘抄自《iOS开发进阶》。
对于此部分苹果官方有Demo,超级传送门
Strong整理了这部分内容,并且封装了代码,这是github链接XFontTool;
install
download the XFontExample;
drag the folder XFontExample->XFontTool to your project
Usage
#import "XFontTool.h”
there are just two method
+(BOOL)isDownloadFont:(NSString *)fontName;
+(void)downLoadFontWithFontName:(NSString *)fontName progress:(void(^)(CGFloat pro))progress complete:(void(^)(void))complete errorMsg:(void(^)(NSString *message))errorMsg;
Example Code
NSString *fontName = XChineseFont_YuppySC_Regular;
if ([XFontTool isDownloadFont:fontName]) {
_exampleLabel.font = [UIFont fontWithName:fontName size:40];
return;
}
[XFontTool downLoadFontWithFontName:fontName progress:^(CGFloat pro) {
NSLog(@"progress:%f%%",pro);
} complete:^{
_exampleLabel.font = [UIFont fontWithName:fontName size:40];
} errorMsg:^(NSString *message) {
NSLog(@"errorMessage:%@",message);
}];
Attention
whenever you use the font you should check the font whether you had downloaded;
[XFontTool isDownloadFont:fontName]
欢迎加入iOS交流群 537774852
更多好文