簡體   English   中英

NSString drawinrect無法填充整個矩形

[英]NSString drawinrect not fills whole rect

我在使用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);

您能幫我理解這種行為嗎?

看來APple算法過於激進。

最好的解決方案是將對齊方式設置為UITextAlignmentCenter,這是top正確清除字符的唯一方法。 在我的測試中,石灰中斷與對齊方式UITextAlignmentLeft相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM