Reputation: 954
How can I make a line with the ends rounded? I'm drawing a simple straight line as follows, but cannot get the ends round. ".cornerRadius" doesn't work. Any ideas?
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)
}
}
Upvotes: 22
Views: 11143
Reputation: 51
try it:
.stroke(.blue, style: StrokeStyle(lineWidth: 3, lineCap: .round, lineJoin: .round))
Upvotes: 5
Reputation: 9829
Try replacing:
.stroke(lineWidth: 8.0)
with:
.stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
Upvotes: 47