In SwiftUI Shapes we can make different color strokes by using gradients.
Eg -
@ViewBuilder
func lineWithSecondColorStyleFromPositionN() -> some View {
let n = 0.5
GeometryReader { gr in
Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: gr.size.width, y: gr.size.height))
}
.stroke(
LinearGradient(stops: [
Gradient.Stop(color: .red, location: 0),
Gradient.Stop(color: .red, location: n),
Gradient.Stop(color: .blue, location: n),
Gradient.Stop(color: .blue, location: 1)
], startPoint: .top, endPoint: .bottom),
style: StrokeStyle(lineWidth: 10, lineCap: .butt)
)
}
.frame(height: 200)
}
Is it possible by any means to do the same for stroke styles?
To create something like this -
Stroke Style 1(Full Line) from 0 to n
,
Stroke Style 2(Dashed) from n
to 1.
Where n
can be any floating number 0<=n<=1