iOS 动态中文系统字体下载

简介

对于很多小型企业和开发人员,要想使用中文字体可能会涉及很多版权问题,苹果提供了很多系统中文字体,以供免费使用

使用

字体名称:代码中使用的字体名称为PostScript,我们可以在Mac字体册中查看

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:0];
[dict setValue:@"DFWaWaSC-W5" forKey:NSFontAttributeName];
CTFontDescriptorRef def = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)dict);
    
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:(__bridge  id)def, nil];
CFRelease(def);

__block BOOL down = NO;
   CTFontDescriptorMatchFontDescriptorsWithProgressHandler((__bridge CFArrayRef)arr, NULL, ^bool(CTFontDescriptorMatchingState state, CFDictionaryRef  _Nonnull progressParameter) {
        
NSDictionary *process = (__bridge NSDictionary *)progressParameter;
        double percent = [[process objectForKey:(__bridge id)kCTFontDescriptorMatchingPercentage] doubleValue];
        switch (state)
        {
            case kCTFontDescriptorMatchingDidBegin:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingDidFinish:
            {
                down = YES;
            }
                break;
            case kCTFontDescriptorMatchingWillBeginQuerying:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingStalled:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingWillBeginDownloading:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingDownloading:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingDidFinishDownloading:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingDidMatch:
            {
                
            }
                break;
            case kCTFontDescriptorMatchingDidFailWithError:
            {
                
            }
                break;
                
            default:
                break;
        }
        
        
        return YES;
    });
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容