ios – SwiftUI – Shapes in ForEach view with completely different stroke coloration and line width Not Working

[ad_1]

I’ve an array of Path and I’ve a customized form.

struct MyShape: Form {
    var path: Path

    func path(in rect: CGRect) -> Path {
        path
    }
}

I’m drawing a number of shapes utilizing a ForEach view. I need to assign completely different line widths and colours to every view

struct MyView: View {

    @State non-public var paths: [Path] = []
    @State non-public var lineWidths: [Double] = []
    @State non-public var colours: [Color] = []

    var physique: some View {
        ZStack {
            ForEach(0..<paths.depend, id: .self) { index in
                MyShape(path: paths[index])
                    .stroke(lineWidth: lineWidths[index])
                    .foregroundColor(colours[index])
            }
        }

    }
}

The paths are drawing advantageous however the entire shapes are taking linewidth and coloration the identical as the primary form. For instance, if I’ve the colours

@State non-public var lineWidhts: [Double] = [4.0, 10.0, 20.0]
@State non-public var colours: [Color] = [Color.red, Color.blue, Color.yellow]

The entire shapes have 4.0 line width and pink coloration as an alternative of getting completely different colours.

[ad_2]

Leave a Reply