2

I have a horizontal stackview with button and label

Case 1: Button text is dynamic and size of it should fit to text. So I added hugging and compression to required. This works perfectly

Case 2: But when my label is hidden, Button takes entire space of stackview. How can i avoid that?

I need my button width fixed to fit the title. Please refer below screen how it looks

ALL Constraints are added in storyboard. I don't want to do it programatically

enter image description here

Please advice

Community
  • 1
  • 1
Ashh
  • 569
  • 1
  • 6
  • 28

1 Answers1

1

There are multiple ways for that.

enter image description here

First stackView: Your normal case.

Second stackView:

  • The label.text has " " value.
  • Adding a blank text could make the stackView height increase if you don't explicitly add a height constraint for the stackView.
  • Also, the button has a width constraint.

Third stackView:

  • The label alpha is set to 0.
  • The button has a width constraint.
Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95