5

I want to place label to the bottom of image and align them vertically. I've tried to use StackView to achieve this. And I get this:

enter image description here

Is there any way to show all label's text correctly? Label text can have any length.

Semyon Tikhonenko
  • 3,872
  • 6
  • 36
  • 61

2 Answers2

3
  • Constrain the label and the stack view to have equal widths.
  • Set the horizontal content hugging priority of the label to 249 (so it can get wider if it's narrower than the image).
  • Set the horizontal content compression resistance of the label to 751 (so it forces the stack view to be wider if necessary).

constraints

Result:

resulting layout

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • How it would work if the label is smaller than image? – Semyon Tikhonenko Jan 20 '16 at 20:55
  • Then the label will be aligned according to its text alignment setting. Try it and see. – rob mayoff Jan 20 '16 at 20:58
  • All those red lines around your views are constraints that aren't satisfied. Choose Editor > Resolve Auto Layout Issues > All Views > Update Frames. Also, the red arrow next to the scene name in the outline means there are errors or missing constraints. Click the arrow to get a list of the problems. – rob mayoff Jan 20 '16 at 21:10
2

Don't fix the width of stackview.

Change the Alignment property of stackview to Center.

enter image description here

The label will grow itself with the text.

enter image description here

Irfan
  • 5,070
  • 1
  • 28
  • 32