Wrap Text in CGContextShowTextAtPoint

Discussion in 'iOS Programming' started by blackbook1991, Oct 9, 2011.

  1. blackbook1991 macrumors newbie

    Oct 9, 2011

    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:
    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));
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Don't use CGContextShowTextAtPoint. Use one of the NSStringDrawing drawing methods like drawInRect.
  3. North Bronson macrumors 6502

    Oct 31, 2007
    San José
    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.

Share This Page