1

In the NIB editor I specify a UILabel with 0 lines (i.e. unlimited) and enter some text that takes up a full line. However, this causes the UILabel to expand to take up 2 lines worth of space (as shown). Any way to prevent this?

Updated with clearer image. This is inside a custom cell, with constraints, 2 cells shown in the TableView. I want the first UILabel to be sized correctly, for 1 line, like the 2nd.

enter image description here

Gaurav Sharma
  • 2,680
  • 3
  • 26
  • 36
  • maybe read the documentation of `UILabel` and recognize that setting the number of lines to 0 will cause the label to auto-expand? – The Paramagnetic Croissant May 05 '15 at 19:10
  • I see two labels each taking up one line? It's hard to tell on that screen shot. – Frankie May 05 '15 at 19:13
  • Image updated, with comment added. – Gaurav Sharma May 05 '15 at 19:24
  • This reminds me of a bug I have encountered (that is still around) that I documented here: http://stackoverflow.com/questions/23575958/uilabel-size-incorrect-for-single-line-of-text-with-linespacing-and-multiple-col The gist of it is that setting a custom line spacing + multiple colors in an attributed string causes the view to get a size for 2 lines when there is only 1. Your bug may be related, it is possible there are some other attributes that in combination cause this issue. – Dima May 05 '15 at 19:25

2 Answers2

1

Unticking "Preferred Width" under Label in Size Inspector resolved the issue.

Gaurav Sharma
  • 2,680
  • 3
  • 26
  • 36
0

This looks like a constraints issue. Your label has the correct number of lines, which is 1. However, the label height is different for the label in the first cell vs the second cell. Notice that the top spacing (from the top of the cell to the top of the label) is the same in both cells, as is the spacing from the bottom of the cell to the top of the second label. Likewise, the bottom of your second label to the bottom of the cell is also the same. Therefore, I would say your issue lies in the constraint of the height of the bottom label.

Frankie
  • 11,508
  • 5
  • 53
  • 60