UITextView の背景線を描画しようとしています。これらの線を描画するために使用したコードは次のとおりです。
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);
そしてその結果が写真に示されています
最初の行は正しく取得されているように見えますが、次の行はテキストと整列していません。
私はおそらくここで何を逃しましたか?ローカリゼーション設定と何か関係がありますか?