Search code examples
iosxcodeinterface-builder

Set maximum label width using the minimum amount of lines


Hi I'm facing this issue:

I am trying to achieve this:

I want that the red label doesn't use more than the 50% of the cell width, but if it needs less space or it is a multiline calculate the real width of the cell instead of leaving a big blank space where there is no text.

Goal

What I am getting:

If I force it to be 50% of the width:

Wrong experiment

If I set width equals or less than 50% of the width:

enter image description here enter image description here


Solution

  • Fixed! To make that a multiline label gets the real width instead of the maximum with but using the minimum amount of lines like this:

    Goal

    instead of this:

    Not desired

    You have to set the horizontal compression resistance priority to 1000.

    how to do it