iOS-动态下载中文字体

从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
更多好文

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容