iOS字体 动态下载系统提供的多种中文字体

活力赛事直播

__block BOOL errorDuringDownload =NO; CTFontDescriptorMatchFontDescriptorsWithProgressHandler( (__bridge CFArrayRef)descs,NULL, ^(CTFontDescriptorMatchingState state, CFDictionaryRef progres……

__block BOOL errorDuringDownload =NO;

CTFontDescriptorMatchFontDescriptorsWithProgressHandler( (__bridge CFArrayRef)descs,NULL, ^(CTFontDescriptorMatchingState state, CFDictionaryRef progressParameter) {

double progressValue = [[(__bridge NSDictionary *)progressParameter objectForKey:(id)kCTFontDescriptorMatchingPercentage] doubleValue];

if (state == kCTFontDescriptorMatchingDidBegin) {

NSLog(@"字体已经匹配");

} elseif (state == kCTFontDescriptorMatchingDidFinish) {

if (!errorDuringDownload) {

NSLog(@"字体%@下载完成", fontName);

}

} elseif (state == kCTFontDescriptorMatchingWillBeginDownloading) {

NSLog(@"字体开始下载");

} elseif (state == kCTFontDescriptorMatchingDidFinishDownloading) {

NSLog(@"字体下载完成");

dispatch_async( dispatch_get_main_queue(), ^ {

// 可以在这里修改UI控件的字体

});

} elseif (state == kCTFontDescriptorMatchingDownloading) {

NSLog(@"下载进度 %.0f%% ", progressValue);

} elseif (state == kCTFontDescriptorMatchingDidFailWithError) {

NSError *error = [(__bridge NSDictionary *)progressParameter objectForKey:(id)kCTFontDescriptorMatchingError];

if (error !=nil) {

_errorMessage = [error description];

} else {

_errorMessage = @"ERROR MESSAGE IS NOT AVAILABLE!";

}

// 设置标志

errorDuringDownload = YES;

NSLog(@"下载错误: %@", _errorMessage);

}

return (BOOL)YES;

});