iOS-動態(tài)下載中文字體

從iOS6開始,蘋果開始支持動態(tài)下載官方提供的中文字體到系統(tǒng)中。使用蘋果官方提供的中文字體,既可以避免版權問題,又可以節(jié)省應用體積。該方案適合對字體有較多需求的應用。

——以上摘抄自《iOS開發(fā)進階》。

對于此部分蘋果官方有Demo,超級傳送門

Strong整理了這部分內(nèi)容,并且封裝了代碼,這是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
更多好文

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容