【问题标题】:NSString drawinrect not fills whole rectNSString drawinrect 不填充整个矩形
【发布时间】:2011-03-12 16:58:51
【问题描述】:

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

你可以看到唯一到达整个屏幕的文本行是最后一个,我不知道为什么其他行没有。 这是我的代码:

//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);

您能帮我理解这种行为吗?

【问题讨论】:

    标签: iphone cocoa-touch text nsstring


    【解决方案1】:

    看起来苹果算法过于激进了。

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

    【讨论】:

    • 我尝试设置 UITextAlignmentCenter 甚至 UITextAlignmentRight 但我得到了同样的错误。也尝试设置一个较小的矩形,但同样的情况发生了。解决它的唯一方法是设置更大的字体,大小但我需要小字体。有什么帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2012-02-02
    • 2019-07-06
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    • 2011-06-30
    相关资源
    最近更新 更多