Pauli
Pauli

Reputation: 363

Resize a view within a UIStackView to fill the remaining screen size at runtime

I have the following setup on my storyboard:

UIScrollView
|- UIStackView
    |- View1
    |- View2
    |- View3
    |- View4

Some content inside View1-4 is dynamic, and View2 has a button. If this button is clicked, the ScrollView scrolls to an offset so that View2 is at the top of the visible screen. View2 has a fixed and known height of 100. How can I now resize View3 after the button was clicked and the scrolling was done, so that it fills the remaining part of the screen, working on all devices? Would I need to calculate the screen height and substract View2‘s height? Or is there any lean way with autolayout?

Upvotes: 0

Views: 155

Answers (1)

Rengers
Rengers

Reputation: 15238

You could create a constraint for the height of View3 that is equal to the root view height, with a constant of -100. Then you could simply toggle isActive on this constraint, and View3 should automatically resize the way you want it.

Upvotes: 1

Related Questions