Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round Corner of Path Line SwiftUI

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)
    }
}
like image 512
Nas5296 Avatar asked Oct 31 '19 02:10

Nas5296


People also ask

How do I set the corner radius in SwiftUI?

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.

How do you round the corners of a view SwiftUI?

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.

How do you label corner radius in Swift?

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..


1 Answers

Try replacing:

.stroke(lineWidth: 8.0)

with:

.stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
like image 176
TylerP Avatar answered Sep 28 '22 09:09

TylerP