Starting to move from springs and structs layout to auto layout and have some questions regarding \"Intrinsic Size\" setting.
If you set \"Intrinsic Size\" of some view
Every view that contains content can calculate its intrinsic content size. The intrinsic content size is calculated by a method on every UIView instance. This method returns a CGSize instance
When you set the intrinsic size to "Placeholder", you tell the Xcode layout system that your view will have size dependent on its content (like a label can be dependent on its text content). The system only knows and maintains its own types of views with intrinsic size. If you wish to have a similar experience with a view of your own, to consider the view as if it has an intrinsic size. Then you set up your constraints as if the view should grown or shrink depending on its content. Finally, you implement the intrinsicContentSize
method to calculate and return the correct size of the content. If the content changes and a new calculation should be performed, you call invalidateIntrinsicContentSize
on your view. Depending on how you have set up your constraints, your view will either grow and/or shrink, or it will be static (like you can set a width and height constrains on a label, and it remains static).
When Intrinsic size set to Placeholder, containerView calculates its own height according to its subView(containeeView)
containerView grows or shrinks according to what's inside of it.
-Set width and position for view, not height -set view.intrinsicSize = Placeholder -Put a label inside view -snap label to all borders of the view -do not set height for label (or set height with >= operator. Not = operator) -set label as lines=0, lineBreak=WordWrap
According to content size, label will grow or shrink in height. view will grow or shrink height according to label height.
if you familiar with wrap_content
from android , the intrinsicContentSize
is same as wrap_content.