Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

blackbook1991

macrumors newbie
Original poster
Oct 9, 2011
1
0
Hi!

I'm trying to display texts in a CGContext and I want to know how to wrap the texts. How can I make this possible?

Here's my line of code:
Code:
NSString *text1 = @"These three first articles describe the God in whom we believe. The pictures of the triangle represents the Triune God), of Jesus Christ and of the dove representing the Holy Spirit are grouped together in order to manifest their intimate relationships and unity.";
    
    
    char* text	= (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding]; 
    
    CGContextSelectFont(ctx, "Arial", 30, kCGEncodingMacRoman);
	CGContextConcatCTM(ctx, transform);
	CGContextDrawImage(ctx, imageRect, [image CGImage]);
    
    CGContextSetTextDrawingMode(ctx, kCGTextFill);
    CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); 	
    CGContextShowTextAtPoint(ctx,10,10,text, strlen(text));
 
Don't use CGContextShowTextAtPoint. Use one of the NSStringDrawing drawing methods like drawInRect.
 
Core Graphics is pretty dumb about text; it doesn't know how to convert Unicode to glyphs or how to wrap lines.

You could use Core Text, which is a C-based framework that works with Core Graphics. The advantage of using Core Text (as opposed to the UIKit String Drawing methods) is that you can use almost exactly the same code on the desktop version of the OS.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.