0

I've just started learning of SwiftUI and I'm trying to make simple view:

var body: some View {
        VStack(spacing: 30) {
            Spacer()

            Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
            
            TextField("Some text", text: $model.trakingUrl) { val in
                
            }
                .textFieldStyle(PrimaryTextFieldStyle())
            Button {
                // code
            } label: {
                Text("Next")
                    .padding()
                    .background(Color.yellow)
            }
            .border(.black)
        }
    }

I want to align all elements to the bottom and it works

enter image description here enter image description here

BUT as you can see the background of the button stretches out of the container and safearea. Without Spacer() it works but it gives wrong alignment. Adding some element after the Button also visually fixes this problem.

Please

  1. Explain this behavior, why it happens?
  2. How to fix it properly?

Version 14.2

Sergey Bogatyrev
  • 93
  • 1
  • 1
  • 5

0 Answers0