1

Within a regular UIView that uses basically all screen space I put a Stack View with vertical and horizontal alignment, and a constraint such that the images inside have the same size.

Thus, I am expecting that once the size of the whole Stack View changes, it will still be centered and all the images will have the same size. In fact, if I add a constraint to set its height, everything works beautifully.

The problem comes when I want to set this height programatically and not as a constraint. For this, I simply do:

print(myStackview.frame.size)
myStackview.frame.size.height = 400
print(myStackview.frame.size)

Absolutely nothing happens to the Stackview from the user's perspective but in fact, when I print its size the dimensions are different and it seemed to work.

I wrote this lines within viewDidLoad and viewDidLayourSubviews and nothing happened. What can it be?

Shivam Tripathi
  • 1,405
  • 3
  • 19
  • 37
jmlipman
  • 172
  • 10

1 Answers1

1

Don't change the stack view's frame. Add a height constraint to stack view and change it's constant. You can change the constraint's constant value programmatically:

let heightConstraint = heightAnchor.constraint(equalToConstant: 200)
heightConstraint.isActive = true

//later in code
heightConstraint.constant = 400
juhan_h
  • 3,965
  • 4
  • 29
  • 35