I'm following the "Dynamic Stack View" part of this Stack View Apple tutorial, and I'm running into an constraint issue in Interface Builder if I leave the UIStackView
(within the UIScrollView
) empty, as opposed to putting a UIButton
inside it. I want my UIViewController
to dynamically create all of the arrangedSubviews
, so I don't want to leave a single UIView
in there that I will just have to handle or delete programmatically.
I can ignore the error and it will still work as I want, with no runtime constraint errors. However, I don't want to leave constraint issues within my xib/nib.
What's the cleanest way to satisfy Interface Builder? If I add a concrete height constraint, then I have to create an outlet for it and delete it programatically. That seems overly invasive and I'd rather leave as much Auto Layout in the xib/nib as possible.
It turns out that in order to satisfy Interface Builder, the UIScrollView
needs to have a height for its contents, and it won't assume a height of 0
. So since the UIStackView
is the content view, it needs to have a height. Even though at runtime it will have content, and thus a height, Interface Builder needs to have a fallback. So therefore, set the Intrinsic Size.
It's at the bottom of Size inspector:
Change Intrinsic Size from Default (System Defined) to Placeholder and set the Height to whatever you want. Something large enough to help while designing in Interface Builder is probably a good idea. You can leave Width set to whatever, or check the None checkbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With