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)
}
}
Any SwiftUI view can have its corners rounded using the cornerRadius() modifier. This takes a simple value in points that controls how pronounced the rounding should be.
You can round the corners of any SwiftUI view by using the cornerRadius() modifier. Simply add a value to the cornerRadius to control how rounded you want the view to be.
masksToBounds = true" is an important code, if you apply corner radius to a label and if it dosen't work than adding this will definitely add the corner radius to a particular label.. So this should be the correct answer..
Try replacing:
.stroke(lineWidth: 8.0)
with:
.stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With