Open andi357 opened 5 years ago
And how your solution will work for iPad and iPhone? Different preferredLayoutWidth
?
@mikestalker Yes, similar to UILabel
s preferredMaxLayoutWidth
you need to set the value depending on the available space, which might be (but doesn't have to) different on iPhone and iPad.
this saved me 🙏 thank you very much!
This pull requests adds the ability to calculate the
intrinsicContentSize
ofTagListView
without requiring a full layout-run. This is for example the case if some one wants to pre-calculate the sizes ofUICollectionViewCell
s (withsystemLayoutSizeFitting (...)
) that have aTagListView
embedded.In my case, the
intrinsicContentSize
was always wrong (height: number of tag x tag-height) because the tag list inside my static prototyping cell (which is used for size-pre-calculation) was not layouted yet. And since layouting the whole cell is more expensive then usingsystemLayoutSizeFitting()
while gathering the correct cell sizes is critical for scrolling performance of the whole collection view, I had to find a way to calculate theintrinsicContentSize
without that dependency from the view's frame.BTW: Even Apples documentation for
intrinsicContentSize
says:My solution is inspired from
UILabel
'spreferredMaxLayoutWidth
, since multiline labels have the same requirement to calculate their height depending of their width, which they don't know prior layouting.So in
rearrangeViews()
theTagListView
uses the newly introducedpreferredLayoutWidth
property (if set to a proper value) for calculating the distribution of all tags (instead offrame.width
). The getter ofintrinsicContentSize
then looks for the widestrowView
to determine the tag list view's intrinsic width.When using autolayout, the tag list view will then be sized based on it's
intrinsicContentSize
.