Created
April 28, 2011 05:38
-
-
Save stuartcarnie/945862 to your computer and use it in GitHub Desktop.
Preload a Core Text font descriptor if you are having performance issues in iOS 4.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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
Actually, it seems it's correctly preloading these fonts, because the delay before first text render is much better when the preloading code is active than when it's not. However, there is still a small delay left on first text render. Did you experience this too?