Determining the internal size of a UIStackView before displaying it on the screen

I would like to determine the size of the stack object before displaying it on the screen. The idea is to use it as part of a pull menu at the bottom of the screen, but when I request an object before it appears, it has a size (-1, -1). Is there anything I should do first of all before addressing the size of incremental content?

+5
source share
1 answer

UIStackView does not have its own content. You get -1 because that is the value of UIViewNoIntrinsicMetric .

Instead, ask his fit size:

 let size = stackView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) 
+12
source

Source: https://habr.com/ru/post/1246362/


All Articles