Gaurav Sharma
Gaurav Sharma

Reputation: 2770

UILabel - single line of text takes up 2 lines in iOS 8 Xcode 6.3

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

Upvotes: 1

Views: 866

Answers (2)

Gaurav Sharma
Gaurav Sharma

Reputation: 2770

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

Upvotes: 1

Frankie
Frankie

Reputation: 11928

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.

Upvotes: 0

Related Questions