0

In a UITextView I want to draw ruled lines along with the text. For that, I subclass UITextView and overwrite drawRect. Seing a few post on the subject (including on this site), that seems the right way to start.

Here is the loop where I draw the lines:

for (int x=1;x<numberOfLines;x++) {
    yPos=self.font.lineHeight*x+baselineOffset;
    CGContextMoveToPoint(context,self.bounds.origin.x,yPos);
    CGContextAddLineToPoint(context,self.bounds.size.width,yPos);
}

baselineOffset in this code is constant, meaning I step by self.font.lineHeight but seeing the picture below (with the slow shifting between the lines and the text) I am obviously not using the right value for incrementing the y coordinate (here called yPos). What should I use?

Has anyone got an idea of what could be the problem?

Thank you for any tip.

enter image description here

Michel
  • 10,303
  • 17
  • 82
  • 179

1 Answers1

0

Use font.leading instead of font.lineHeight.

Mercurial
  • 2,095
  • 4
  • 19
  • 33
  • `font.leading' is deprecated in iOS4. I have the same problem, and using font.leading didnt make a better result. – jAckOdE Aug 06 '13 at 05:07