Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

intrinsicContentSize vs. sizeThatFits. What's the difference? What are the use cases for each?

I understand that intrinisicContentSize is part of the AutoLayout API, but other than that, I'm seeing lots of functionality overlap between it and the -sizeThatFits method.

In what circumstance should one be used over the other? When I'm subclassing a UIView, which should I override to make sure my view is sized to its subviews?. Can you give an example of what a typical overridden method would look like for both?

like image 272
zakdances Avatar asked May 01 '13 12:05

zakdances


1 Answers

intrinsicContentSize was added in iOS 6 and as you mentioned is part of the AutoLayout API so anything which supports an earlier iOS won't have access to it. Also, if you turn off auto layout, it doesn't matter which you use and many people who are used to using sizeThatFits will still use it for a while... at least until auto layout gain greater adoption.

like image 102
DBD Avatar answered Nov 03 '22 00:11

DBD