Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI add a -y offset to a view but stretching the view to bottom

Tags:

swiftui

I have 2 views in my code, a VStack and then a custom view.

I am adding an offset to the second view of -75, to move it on top of the first view.

Here is my current code:

Group {
       VStack {
           //First View
           VStack {
               Image("LogoCrest")

                NavigationLink(destination: LocationSearch()) {
                    Text("Find a location")
                    .foregroundColor(Color.white)
                    .bold()
                    .padding()
                }
                .frame(minWidth: 0, maxWidth: .infinity, alignment: Alignment.center)
                .background(Color(red: 81 / 255, green: 175 / 255, blue: 67 / 255))
                .cornerRadius(7)
                .padding()

           }
           .padding(.top, 75)
           .padding(.bottom, 75)
           .frame(minWidth: 0, maxWidth: .infinity, alignment: Alignment.center)
           .background(Color(red: 49 / 255, green: 49 / 255, blue: 49 / 255))

           //Second view
           CircuitList(Circuits: Circuits)
            .offset(y: -75)
           .padding()
       }
     }
    .background(Color(red: 232 / 255, green: 232 / 255, blue: 232 / 255))
    .edgesIgnoringSafeArea(.top)

How can I increase the height of the second view so it can always be at the bottom (see the black line in the image below for my desired extra height)?

My view

like image 610
Matt Ward Avatar asked Sep 15 '19 20:09

Matt Ward


1 Answers

I have found the answer. Since I added y:-75 offset to my view, I had to add y:-75 padding too.

CircuitList(Circuits: Circuits)
    .offset(y: -75)
    .padding()
    .padding(.bottom, -75)
like image 55
Matt Ward Avatar answered Nov 09 '22 13:11

Matt Ward