Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@evadne
Last active May 17, 2016 09:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evadne/5519337 to your computer and use it in GitHub Desktop.
Save evadne/5519337 to your computer and use it in GitHub Desktop.
Loading Custom Fonts with CTFontManager
CTFontManagerRegisterFontsForURLs((__bridge CFArrayRef)((^{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
NSArray *resourceURLs = [fileManager contentsOfDirectoryAtURL:resourceURL includingPropertiesForKeys:nil options:0 error:nil];
return [resourceURLs filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSURL *url, NSDictionary *bindings) {
CFStringRef pathExtension = (__bridge CFStringRef)[url pathExtension];
NSArray *allIdentifiers = (__bridge_transfer NSArray *)UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, pathExtension, CFSTR("public.font"));
if (![allIdentifiers count]) {
return NO;
}
CFStringRef utType = (__bridge CFStringRef)[allIdentifiers lastObject];
return (!CFStringHasPrefix(utType, CFSTR("dyn.")) && UTTypeConformsTo(utType, CFSTR("public.font")));
}]];
})()), kCTFontManagerScopeProcess, nil);
@matt-curtis
Copy link

Wow this is useful. Nice work! Could be more readable though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment