Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline UILabel height increases even when the text is one line long

I am using a UILabel within a tableViewCell. Some of the cells have texts that are one line, and some 2 lines. I have set the trailing space, leading space and top space from superview constraints to the label. Following are the settings:

  • lines = 0
  • Line Breaks: Word Wrap (tried other options as well)

If the text crosses a particular length, for some reason, the label height seems to have increased to accommodate 2 lines, though the text is only one line. As show below (background is red for reference): enter image description here

For example, In the first row, the actual text is one line, but the height is increased when compared to the other rows.

Is there any reason why it might be happening so? I am not setting the height anywhere from the code.

EDIT

Also, I have set a custom font for UILabel throughout out the App using the following:

[[UILabel appearance] setFont:myFont];

I am not sure if that should cause any issue..

Also, the screen shot of the constraints set are:

enter image description here

like image 662
Shanti K Avatar asked Oct 23 '25 04:10

Shanti K


1 Answers

Got the same issue. After checking content hugging priorities got the same results. Finally found that it was caused by Label-Preferred Width set to Explicit in Metrics Tab, in label configuration.

Unchecked and solved =)

like image 142
Sori Alex Avatar answered Oct 25 '25 19:10

Sori Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!