我正在尝试绘制 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);
And the result is shown in the picture
![enter image description here](https://i.stack.imgur.com/nSyGi.png)
看起来它正确地获得了第一行,但以下行与文本不对齐。
我在这里可能错过了什么?与本地化设置有什么关系吗?
您可能想检查this https://github.com/danielamitay/DALinedTextView out.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)