Created
April 25, 2011 20:38
-
-
Save jocafa/941167 to your computer and use it in GitHub Desktop.
Fancy Strings
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
- (void)drawRect:(CGRect)rect | |
{ | |
// Drawing code | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
CGContextClearRect(ctx, rect); | |
[[UIColor darkGrayColor] set]; | |
CGContextFillRect(ctx, rect); | |
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:@"Herp Derp."]; | |
NSRange range = NSMakeRange(2, 4); | |
CFStringRef fontstr = CFStringCreateWithCString(kCFAllocatorDefault, "Zapfino", kCFStringEncodingASCII); | |
CTFontRef font = CTFontCreateWithName(fontstr, 18.0, NULL); | |
[attrstr addAttribute:(NSString*)kCTFontAttributeName value:(id)font range:range]; | |
//CGContextTranslateCTM(ctx, 10.0, 10.0); | |
CGContextScaleCTM(ctx, 1.0, 1.0); | |
CGContextSetTextMatrix(ctx, CGAffineTransformMakeScale(1.0, -1.0)); | |
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0.0, 0.0, 320.0, 200.0)]; | |
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attrstr); | |
CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path.CGPath, NULL); | |
CFRelease(framesetter); | |
CTFrameDraw(textFrame, ctx); | |
CFRelease(textFrame); | |
UIGraphicsPushContext(ctx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh dear...