我需要在 UIView 中绘制一条水平线。最简单的方法是什么。例如,我想在 y-coord=200 处画一条黑色水平线。
我没有使用 Interface Builder。
最佳答案
也许这有点晚了,但我想补充一点,还有更好的方法。 使用 UIView 很简单,但是比较慢。此方法会覆盖 View 自身的绘制方式并且速度更快:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point
CGContextAddLineToPoint(context, 20.0f, 20.0f); //draw to this point
// and now draw the Path!
CGContextStrokePath(context);
}
关于ios - 在 UIView 中画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3128752/