4265756b69
4265756b69

Reputation: 57

How to fix button over the View SwiftUI

I have a little issue and I do not know how can i solve this. Basically, i have a SwiftUI View which contains more "little" views, when the button is pressed, is changhing to the next View, but my Button is always over my view. How can I put the button on the same level with the View ?

 var body: some View {
        ZStack {
          
            ZStack {
                switch onboardingState {
                    
                case 0 :
                    welcomeSection
                        .transition(transition)
                case 1 :
                    detailOrder
                        .transition(transition)
                case 2 :
                    detailOrder2
                        .transition(transition)
                default:
                    EmptyView()
                }
            }
            VStack {
                Spacer()
                bottomButton
            }
            
            .padding(30)
        }
       
    }

Picture

Upvotes: 1

Views: 1420

Answers (2)

ahmad mohammadi
ahmad mohammadi

Reputation: 46

You are using Zstack which is used for putting views on top of each other. change outer ZStack to Vstack and your problem is solved.

Upvotes: 0

bdeviOS
bdeviOS

Reputation: 563

Try this

    var body: some View {
           VStack {
             
               ZStack {
                   switch onboardingState {
                       
                   case 0 :
                       welcomeSection
                           .transition(transition)
                   case 1 :
                       detailOrder
                           .transition(transition)
                   case 2 :
                       detailOrder2
                           .transition(transition)
                   default:
                       EmptyView()
                   }
               }
             
                   Spacer()
                   bottomButton
               
               .padding(30)
           }
          
       }

Upvotes: 2

Related Questions