2

I've got a UILabel with variable length content, when the content is long I want the text to be truncated. This part works:

enter image description here

However if the text is short then this is how it appears:

enter image description here

I don't understand why the start of the text is shifted to the right - because the text is left aligned and there is a 8.5 constraint between it leading edge and the UILabel's to its left trailing edge:

enter image description here

enter image description here

When the text is short, why is it being shifted to the right?

How can I get it to be aligned to the left and be truncated when its too long to fit between the UILabel on the left and the disclosure indicator to the right?

Umair Afzal
  • 4,947
  • 5
  • 25
  • 50
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

2

You have two labels. One says “Comment” and the other says “Short text”. These together are not enough to fill the horizontal space available, so UIKit stretches one to fill the space. It's stretching the “Comment” label but you want it to stretch the “Short text” label instead.

To prevent it from stretching “Comment”, increase the horizontal content hugging priority of the “Comment” label to 750.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848