Обтекание текста в CGContextShowTextAtPoint - PullRequest
1 голос
/ 07 октября 2011

Я пытаюсь отобразить текст в CGContext, и я хочу знать, как обернуть тексты.Как я могу сделать это возможным?

Вот мой код:

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.";


- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {


if(index>[images count]-1)return;

UIImage *image = [images objectAtIndex:index];
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
CGAffineTransform transform = aspectFit(imageRect,
                                        CGContextGetClipBoundingBox(ctx));

NSString *text1 = [script objectAtIndex:index];

char* text  = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding]; 

CGContextSelectFont(ctx, "Arial", 30, kCGEncodingMacRoman);

CGContextConcatCTM(ctx, transform);
CGContextDrawImage(ctx, imageRect, [image CGImage]);


CGContextSetTextPosition(ctx, 0.0f, round(30 / 4.0f));
CGContextSetTextDrawingMode(ctx, kCGTextFill);
CGContextSetRGBFillColor(ctx, 0, 0, 0, 1);  
CGContextShowTextAtPoint(ctx,10,10,text, strlen(text)); 

}

1 Ответ

1 голос
/ 17 октября 2011

Если вам нужно более сложное форматирование текста (например, обтекание), используйте вместо него Core Text.Чтобы отобразить простую строку в прямоугольнике, используйте

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
CGPath p = CGPathCreateMutable();
CGPathAddRect(p, rect);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,0), p, NULL);
CTFrameDraw(frame, context);
...