從iOS6開始,蘋果開始支持動態(tài)下載官方提供的中文字體到系統(tǒng)中急灭。使用蘋果官方提供的中文字體姐浮,既可以避免版權問題,又可以節(jié)省應用體積葬馋。該方案適合對字體有較多需求的應用卖鲤。
——以上摘抄自《iOS開發(fā)進階》。
對于此部分蘋果官方有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
更多好文