Constraint for views in SwiftUI

Hi. I'm having this situation: Let's say I have 3 views like this: VStack { View A View B View C }

Now I'm using padding() but view B's height is dynamic -> the issue is view C will be jumping up and down when view B's height changes -> I want to set a constraint (I know SwiftUI removed constraint) from view C to view A to ignore the view B's height changing.

Any idea? Thanks.

You can use the Spacer() view which will take up all available space. It will also share this space equally when there are multiple.

VStack {
    ViewA()

    Spacer() // push ViewA to the top

    ViewB() // takes up the available space

    Spacer() // push ViewC to the bottom

    ViewC()
}


You could also give ViewB a fixed height but I guess you don't want to do that.

Constraint for views in SwiftUI
 
 
Q