drw
drw

Reputation: 943

determining the intrinsic size of a UIStackView before display on the screen

I would like to determine the instrinstic size of a stack view before displaying it on the screen. The idea is to use it as part of a pull up menu from the bottom of the screen but when I query the object before it appears it has size (-1,-1). Is there anything I should do first before my call to instrinsic content size?

Upvotes: 17

Views: 11334

Answers (1)

rob mayoff
rob mayoff

Reputation: 385998

UIStackView has no intrinsic content size. You're getting -1 because that is the value of UIView.noIntrinsicMetric.

Instead, ask for its fitting size:

let size = stackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)

Upvotes: 54

Related Questions