The easiest way? Something like that:
CGContextRef context = UIGraphicsGetCurrentContext(); // Flip the coordinate system CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); // Create a path to render text in CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, self.bounds ); // An attributed string containing the text to render NSAttributedString* attString = [[NSAttributedString alloc] initWithString:...]; // create the framesetter and render text CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL); CTFrameDraw(frame, context); // Clean up CFRelease(frame); CFRelease(path); CFRelease(framesetter);
source share