CGRect下面的代码是我在制作 pdf 文档时如何绘制一些文本的示例。我需要计算使用comment1CGRect绘制的确切大小,以便comment2、comment3等都从页面上的正确位置开始。
变量currentLine跟踪CGRect页面末尾的位置。它适用于简短的评论,但不适用于后续评论重叠的长评论。字体和字体大小是正确的。
textRect = CGRectMake(60, currentLine, 650, 300);
myString = self.comments1.text;
[myString drawInRect:textRect withAttributes:_textAttributesNotBold ];
CGSize contentSize = [myString sizeWithAttributes: @{NSFontAttributeName: [UIFont fontWithName:@"Arial" size:12]}];
currentLine = currentLine + contentSize.height;
我想知道问题是否与CGRectMake使用 650 宽度有关。这似乎没有考虑到CGSize...... ....在计算contentSize.heightsizeWithAttributes时假设的宽度是多少?CGSizesizeWithAttributes
或者有没有更好的方法来做到这一点?