Help

There text fields move up when I press the Net Worth button. I know that it's because everything is in VStack which causes the text to push everything up, but I don't know how to fix it. Maybe I also need to move the buttons down a little bit also. Could anyone please help?

import SwiftUI

struct Calculate: View {
@State private var Salary = ""
@State private var Assets = ""
@State private var Liabilities = ""
@State var showDetails = false
@State private var showButton = true
var body: some View {

NavigationView {

        VStack {
          
            TextField("Your Salary", text: $Salary)
                  .keyboardType(.numberPad)
                .textFieldStyle(RoundedBorderTextFieldStyle())
            .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
                .background(Color.white)
                .clipShape(RoundedRectangle(cornerRadius: 8))
                .cornerRadius(5)
                                                         
                                                .padding(.all, 15.0)
                                            
                                                .background(Color.init(red: 50/255, green: 50/255, blue:50/255))
            .offset(x: 0, y: -10)

            TextField("Your Assets", text: $Assets)
            

                  .keyboardType(.numberPad)
                .textFieldStyle(RoundedBorderTextFieldStyle())
            .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
                .background(Color.white)
                .clipShape(RoundedRectangle(cornerRadius: 8))
             
            .cornerRadius(5)
                                                     
                                            .padding(.all, 15.0)
                                        
                                            .background(Color.init(red: 50/255, green: 50/255, blue:50/255))
            .offset(x: 0, y: -35)

                TextField("Your Liabilities", text: $Liabilities)
                      .keyboardType(.numberPad)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
    .padding(EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10))
        .background(Color.white)
        .clipShape(RoundedRectangle(cornerRadius: 8))
        .padding(.bottom, 0)
                    .cornerRadius(5)
                                       
                              .padding(.all, 15.0)
                          
                              .background(Color.init(red: 50/255, green: 50/255, blue:50/255))
                    .offset(x: 0, y: -50)
         
            Button(action: {
                self.showDetails = true

            }) {
                                                         Text("Net Worth")
                                                     }
            if showDetails {
               
         
                
                Text("You have a net worth of ") + Text("5 dollars!")
                NavigationLink(destination: showWhy().navigationBarTitle("") .navigationBarHidden(true)) { Text("Hello")
                   
                    
                }
              
                
            }
            else {
                Text("Enter Some Numbers!")
            }
         
            
    }
    .offset(x:0, y: -100)

}

}

    

}
Terms of Service

Privacy Policy

Cookie Policy