Search code examples
xcodeautolayoutuistackview

Why does my view debugger show a different layout and how can I match it?


Why does my view debugger show a different value and how can I make my app match it?

My view debugger is showing this (this is the correct view): enter image description here

But my iPhone is incorrectly showing this: enter image description here

I spoke to someone I know and they said that the debugger lays out the subviews again. How can I trigger this same thing in my application?

This is what my hierarchy looks like:

---UICollectionView
----UICollectionViewCell
-----UIStackView (vertical, scale to fill)
------UILabel (hugging and compression are 1000 for vertical and horizontal)
-------UIImageView (aspect fill, hugging and compression are 750 for vertical and horizontal)

If I begin my app in portrait, all my views layout correctly. If I begin my app in landscape, then I have that incorrect overlay that you see in the image. Any help?

Thanks!


Solution

  • You should set imageView.clipToBounds = true (or any other UIView's) either in code or in IB.

    Apple Documentation Reference

    A Boolean value that determines whether subviews are confined to the bounds of the view. Setting this value to true causes subviews to be clipped to the bounds of the receiver. If set to false, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is false.