Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

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!!!

like image 319
Benjamin Clanet Avatar asked Jul 02 '19 16:07

Benjamin Clanet


1 Answers

You have to add a Spacer view above the text.

struct ContentView : View {
    var body: some View {
        VStack {
            Spacer() // ←- here
            Text("Test")
        }
    }
}
like image 159
LinusGeffarth Avatar answered Nov 05 '22 07:11

LinusGeffarth