i'm trying draw background line of UITextView, here is the code i used to draw those lines
CGContextBeginPath(context);
CGContextSetStrokeColorWithColor(context, self.horizontalLineColor.CGColor);
CGContextSetLineWidth(context, kDashedBorderWidth);
CGContextSetLineDash(context, 0, kDashedLinesLength, kDashedCount) ;
CGFloat baseOffset = 9.0f + self.font.descender;
CGFloat boundsX = self.bounds.origin.x;
CGFloat boundsWidth = self.bounds.size.width;
NSInteger firstVisibleLine = MAX(1, (self.contentOffset.y / self.font.lineHeight));
NSInteger lastVisibleLine = ceilf((self.contentOffset.y + self.bounds.size.height) / self.font.lineHeight);
for (NSInteger line = firstVisibleLine; line <= lastVisibleLine; ++line)
{
CGFloat linePointY = (baseOffset + (self.font.lineHeight * (float)line));
CGContextMoveToPoint(context, boundsX, linePointY);
CGContextAddLineToPoint(context, boundsWidth, linePointY);
}
CGContextClosePath(context);
CGContextStrokePath(context);
And the result is shown in the picture
It seem like the it get the first line correctly but the following lines are not aligned with the text.
What did i probably miss here? Is there anything to do with localization setting?