Skip to content

Instantly share code, notes, and snippets.

@joelrfcosta
Forked from stuartcarnie/gist:945862
Last active December 16, 2015 11:09
Show Gist options
  • Save joelrfcosta/5425437 to your computer and use it in GitHub Desktop.
Save joelrfcosta/5425437 to your computer and use it in GitHub Desktop.
Preload fonts using CGD
#import <CoreText/CoreText.h>
...
// preload
dispatch_queue_t queue = dispatch_queue_create("com.company.worker", NULL);
dispatch_async(queue, ^(void) {
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setObject:@"Helvetica" forKey:(id)kCTFontFamilyNameAttribute];
[attributes setObject:[NSNumber numberWithFloat:36.0f] forKey:(id)kCTFontSizeAttribute];
CTFontDescriptorRef fontDesc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);
CTFontRef matchingFont = CTFontCreateWithFontDescriptor(fontDesc, 36.0f, NULL);
CFRelease(matchingFont);
CFRelease(fontDesc);
});
dispatch_release(queue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment