Last active
December 13, 2016 09:40
-
-
Save darcyliu/8168894 to your computer and use it in GitHub Desktop.
Simple CoreText with CTFrameDraw
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
CGContextRef context = UIGraphicsGetCurrentContext(); | |
// Flip the coordinate system | |
// Make an attributed string | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Hello CoreText!"]; | |
CFAttributedStringRef attributedStringRef = (CFAttributedStringRef)attributedString; | |
// Simple CoreText with CTFrameDraw | |
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attributedStringRef); | |
CGPathRef path = CGPathCreateWithRect(self.bounds,NULL); | |
CTFrameRef frame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0, 0),path,NULL); | |
CTFrameDraw(frame, context); |
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
// Flip the coordinate system | |
CGContextSetTextMatrix(context, CGAffineTransformIdentity); | |
CGContextTranslateCTM(context, 0, self.bounds.size.height); | |
CGContextScaleCTM(context, 1.0, -1.0); |
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
NSDictionary *attrs = @{NSFontAttributeName: [UIFont systemFontOfSize:20], | |
NSForegroundColorAttributeName: [UIColor blueColor], | |
NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle), | |
}; | |
// Make an attributed string | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Hello CoreText!" attributes:attrs]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment