你知道怎么画这样的虚线吗

조승원*_*조승원 0 ios swiftui

像这样 1

你知道怎么画这样的虚线吗

宽度必须是全长。

小智 5

你可以画这样一条线:

GeometryReader { geometry in
        VStack {
            Path{ path in
                path.move(to: CGPoint(x: 0, y: geometry.size.height / 2))
                path.addLine(to: CGPoint(x: geometry.size.width, y: geometry.size.height / 2))
            }
            .stroke(style: StrokeStyle( lineWidth: 2, dash: [5]))
            .foregroundColor(Color(UIColor.blue))
        }
    }
Run Code Online (Sandbox Code Playgroud)

例如,这条线将位于屏幕的中间。只需调整y参数即可移动线条。

结果:

结果