Intrinsic Content Size: Swift’s Sizing Mystery
You may have come across intrinsicContentSize, perhaps through work with
UICollectionView or similar.
But what is it, and what can you do to improve you understanding of this for your journey in Swift?
frame: A rectangle which describes a view’s location and size in it’s superview’s coordinate system
intrinsicContentSize: The natural size for the receiving view, considering only properties of the view itself
I’ve already created a tips article on intrinsic content size which covers something about
intrinsicContentSize. I’ve never been happy with that article as it’s just too abstract.
I just want to see what
intrinsicContentSize and frame mean for views in
UIKit. This is that article.
In the attached repo is a simple view controller (placed in a
UINavigationController) that gives us the opportunity to compare content sizes.
The setup on
viewDidLoad() is really simple for the standard view controller that I’ve created:
I’ve placed some print statements for logging into the View Controller:
Which produces the following output to the console: