我有一个 UIViewController,里面有一个 UIView,我想在上面画一条直线。执行此操作的最简单和高效的方法是什么?我该怎么做呢?它只是一条宽度为 150 的灰色水平虚线。我环顾四周,似乎使用 CGContextSetLineDash 是解决方案,这就是我到目前为止所拥有的:
-(void) drawRect:(CGRect) rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 100);
CGFloat dashes[] = {1,1};
CGContextSetLineDash(context, 2.0, dashes, 2);
CGContextStrokePath(context);
}