The code below is an example of how I use CGRect
to draw some text when making a pdf document. I need to calculate the exact size of the CGRect
being drawn with comment1 so that the ones for comment2, comment3 etc all start in the right place on the page.
The variable currentLine keeps track of where the end of the CGRect
is on the page. It works fine for short comments but not long comments where subsequent comments overlap. The font and font size are correct.
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;
I wonder if the problem is with the CGRectMake
using a 650 width. This does not seem to be taken into account in the CGSize
.... sizeWithAttributes
. What width does the CGSize
.... sizeWithAttributes
assume when calculating the contentSize.height?
Or is there a better way of doing this?