ios – Draw repeating shapes with inset in SwiftUI


I have the following shape drawn with some color & linewidth:

struct CustomShape: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.move(to: .zero)
        path.addLine(to: CGPoint(x: rect.width, y: 0))
        path.addLine(to: CGPoint(x: rect.width/2, y: rect.height))
        path.closeSubpath()
        return path
    }
}

struct ContentView: View {    
    var body: some View {
        ZStack {
            CustomShape()
                .stroke(Color.blue, lineWidth: 5)
                .frame(width: 300, height: 200)
        }
        .ignoresSafeArea()
    }
}

I’d like to draw 2 (possibly more) more rectangles inside the first one each with a different color & line width? Is it possible to inset the shapes as such?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img