ioslayoutautolayoutuistackviewintrinsic-content-size

Should I invalidate intrinsic content size for the whole hierarchy?


Suppose I have the following view hierarchy with Auto Layout enabled:

UIStackView |__ OuterCustomView (overridden intrinsic content size) |__ UILabel |__ InnerCustomView (overridden intrinsic content size) |__UILabel |__UILabel

The labels inside InnerCustomView have dynamically changeable text and font. Whenever a change happens, I call InvalidateIntrinsicContentSize() (Xamarin syntax) on the InnerCustomView instance.

The question is - do I also need to invalidate it manually on the containing OuterCustomView, or is the framework clever enough to take everything from there and re-layout everything up to the topmost UIStackView?


Solution

  • No, you don't need to invalidate intrinsic content size manually. After calling the method invalidateIntrinsicContentSize() for your view system recursively updates all superviews in hierarchy.