swiftswiftui

How to stick my button to the bottom of the view using SwiftUI?


I am experimenting with SwiftUI and just trying to have a button at the bottom. Right now it is centered. Wondering how I could force a view to stick superview's bottom as you would do in AutoLayout.

struct ContentView : View {
    var body: some View {
        VStack {
            Text("Test")
        }
    }
}

Thank you!!!


Solution

  • You have to add a Spacer view above the text.

    struct ContentView : View {
        var body: some View {
            VStack {
                Spacer() // ←- here
                Text("Test")
            }
        }
    }