swiftuilabelstackview

Swift elements's height in stackview


I have a stackView like this.enter image description here

If Data has not images image will be hidden. Then label's text is "" , but label's height is to be long. I want label does not fill stackview. How can I do?


Solution

  • A tableview or a collectionview might be more appropriate for UI containers. They are more suitable for a dynamic feature like you mentioned. Having said that you can play with the configuration of the stack view distribution, spacing, and alignment to dynamically set the StackView to accommodate the sizes you wish. In addition to set sizes of subview using - intrinsiccontentsize

    Here are two links that can help you with that: UIStackView 1 UIStackView 2 Intrinsiccontentsize