If you have a view with no constraints on it, and that view has a subview with left, right, top and bottom constraints of equal size, if the subview's size is increased is it possible for the superview's size to automatically increase to accommodate these constraints?
Thanks.
Yes, you can do that, and it can be done without any code or subclassing. For instance, if you have a label embedded in a view (with numberOfLines = 0), and it has constraints to to all the sides of the superview, as well as a width constraint, the label, and its superview will expand vertically if you put a large string in the label. The superview should still need to have some constraints, like one to the top and left side of its superview, but no size constraints.
This can be done if the superview is a custom subclass of UIView. You can override intrinsicContentSize to return a size related to the size of your super view. Then, when the size of the subview changes, it can invalidate the intrinsic content size. I typically do this in the layoutSubviews part of the superview.
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