Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set stack view height according to its subviews height?

Tags:

xcode

ios

swift

I have a requirement to scroll six different type of view, Each view has different size, One of the views is: About Me. In About Me, I have to show the title (i.e. ABOUT ME) and text below it and label height should be according to text height.

Till Now I have designed this requirement as:

Root View - Stack View * Item 1 with fix height * Item 2 with fix height * UIView as About Me: - Label as title - Label as text with max lines set to 0 and width equals to container width.

The problem is: I can not set fix height of about me UIView and it does not resize according to label text. Please suggest the appropriate solutions.

like image 204
Andro Developer Avatar asked Jan 10 '18 07:01

Andro Developer


1 Answers

Hi you can get the intrinsic height of the stackView like this:

let size = stackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)

I know Im kinda late to reply to this message. But I had the same issue and I found this piece of code. Thought anyone who looking for this might be useful :)

like image 151
NuN Avatar answered Oct 31 '22 10:10

NuN