I'm having difficult time understanding the practical usage of the intrinsic content size, especially the cases when you have to override the existing intrinsic size. It seems like using the widthAnchor and the heightAnchor seem to resolve what the intrinsic content size is trying to solve.
I could achieve the same effect by using the Autolayout anchors:
When the stack view are required to have a size, you can also provide it with the anchors.
Only two use cases I found it to be helpful is if you wanted to manipulate the existing original intrinsicContentSize:
But, I feel like intrinsicContentSize offers far more than simply using it as margins.
The second use case is when you can change the priority by using either setContentCompressionResistancePriority(_:for:) or setContentHuggingPriority(_:for:) to indicate how to respond to the changes in its superview dynamically.
Code Block swift For example if I wanted a certain intrinsic size: class CustomView: UIView { override var intrinsicContentSize: CGSize { return CGSize(width: 200, height: 100) } }
I could achieve the same effect by using the Autolayout anchors:
Code Block swift NSLayoutConstraint.activate([ view.heightAnchor.constraint(equalToConstant: 100), view.widthAnchor.constraint(equalToConstant: 200) ])
When the stack view are required to have a size, you can also provide it with the anchors.
Only two use cases I found it to be helpful is if you wanted to manipulate the existing original intrinsicContentSize:
Code Block swift class CustomView: UIView { override var intrinsicContentSize: CGSize { let originalSize = super.intrinsicContentSize return CGSize(width: originalSize.width + 200, height: 100) } }
But, I feel like intrinsicContentSize offers far more than simply using it as margins.
The second use case is when you can change the priority by using either setContentCompressionResistancePriority(_:for:) or setContentHuggingPriority(_:for:) to indicate how to respond to the changes in its superview dynamically.