NSString drawinrect不填充整个rect

时间:2011-03-12 16:58:52

标签: iphone cocoa-touch text nsstring

我遇到了NSString drawInRect方法的问题。 我有一个非常大的文本要在768x1024大小的Rect上绘制,我得到了这个:

Image text on screen http://img37.imageshack.us/img37/6247/capturadepantalla201103t.png

正如您所看到的那样,到达整个屏幕的唯一文本行是最后一行,我不知道为什么其他行不会。 这是我的代码:

//The drawing rectangle
CGRect textRect = CGRectMake(1, 4, 768, 1024);
[[UIColor blackColor] set];
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
//texto_completo is a very large text String
[texto_completo drawInRect:textRect withFont:font lineBreakMode:UILineBreakModeCharacterWrap     alignment:UITextAlignmentLeft];
CGImageRef cgImage = CGBitmapContextCreateImage(context); 
UIImage *img_con_texto = [[UIImage alloc] initWithCGImage:cgImage];
UIGraphicsPopContext();
CGContextRelease(context);
CGImageRelease(cgImage);

你能帮助我理解这种行为吗?

1 个答案:

答案 0 :(得分:0)

看起来APple算法过于激进。

最好的解决方案是将对齐方式设置为UITextAlignmentCenter,这是top使得字符向右冲洗的唯一方法。在我的测试中,石灰断裂与对齐UITextAlignmentLeft相同。