struct ContentView: View {
    var body: some View {
        VStack(alignment: .leading, content: {
            Text("Hello world!")
                .background(.blue)
                .alignmentGuide(.leading, computeValue: { dimension in
                    return 20
                })
            
            Text("This is some other text!")
                .background(.red)
        })
        .background(.orange)
    }
}

struct ContentView: View {
    var body: some View {
        VStack(alignment: .leading, content: {
            Text("Hello world!")
                .background(.blue)
                .alignmentGuide(.leading, computeValue: { dimension in
                    return 0
                })
            
            Text("This is some other text!")
                .background(.red)
        })
        .background(.orange)
    }
}

struct ContentView: View {
    var body: some View {
        VStack(alignment: .leading, content: {
            Text("Hello world!")
                .background(.blue)
                .alignmentGuide(.leading, computeValue: { dimension in
                    return dimension.width
                })
            
            Text("This is some other text!")
                .background(.red)
        })
        .background(.orange)
    }
}

https://swiftui-lab.com/alignment-guides/

 

Alignment Guides in SwiftUI - The SwiftUI Lab

Alignment guides are a powerful tool that helps layout our SwiftUI views. They often save us from having to use more complex options (e.g, view preferences)

swiftui-lab.com

 

ytw_developer