-
-
Save ytlvy/bf52070533e23435d9a9c2744f7a194c to your computer and use it in GitHub Desktop.
Put an NSAttributedString into a CATextLayer. This works in iOS 5.
This file contains hidden or 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
CATextLayer *textLayer = [CATextLayer layer]; | |
textLayer.backgroundColor = [UIColor whiteColor].CGColor; | |
textLayer.frame = CGRectMake(20, 20, 200, 100); | |
textLayer.contentsScale = [[UIScreen mainScreen] scale]; | |
CTFontRef fontFace = CTFontCreateWithName((__bridge CFStringRef)(@"HelfaSemiBold"), 24.0, NULL); | |
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init]; | |
[attributes setObject:(__bridge id)fontFace forKey:(NSString*)kCTFontAttributeName]; | |
[attributes setObject:[UIColor blackColor] forKey:(NSString*)kCTForegroundColorAttributeName]; | |
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"Lorem Ipsum" attributes:attributes]; | |
textLayer.string = attrStr; | |
[self.view.layer addSublayer:textLayer]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment