路径线的圆角 SwiftUI

19

我该如何制作两端带圆角的线?我正在绘制一条简单的直线,但无法让两端变成圆弧形状。使用“.cornerRadius”并没有起作用。有什么想法吗?

struct Line: View {
    let geoProx: GeometryProxy

    var body: some View {
        Path{ path in
            path.move(to: CGPoint(x: geoProx.size.width/2, y: geoProx.size.height/2))
            path.addLine(to: CGPoint(x: geoProx.size.width/2 - geoProx.size.width/4, y: geoProx.size.height/2))

        }
        .stroke(lineWidth: 8.0)
        .foregroundColor(.white)
        .cornerRadius(10.0)
        .zIndex(1.5)
    }
}
2个回答

41

尝试更换:

.stroke(lineWidth: 8.0)

随着:

.stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))

3
我正在使用Swift 5,但这不起作用。 - lopes710

2

试一下:

.stroke(.blue, style: StrokeStyle(lineWidth: 3, lineCap: .round, lineJoin: .round))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接