1
votes

I'm currently getting extra space on the top and bottom of my UILabel. I have it set to be font size 24, but it can go as small as size 14 (this is to help the text fit when used on smaller phones like 4s) And I have the number of lines constrained to just 7. Other than that, I don't have any constraint forcing it to be a certain height, I'm letting Xcode decide that, but I don't understand why it's adding the extra space. See images for all the settings I have.

UILabel Attributes

enter image description here

Size Inspector Constraints

enter image description here

View in Xcode

enter image description here

Results in iOS

enter image description here

I do have code that is rounding the corners and adding a shadow, but I don't think it is affecting the top and bottom gaps since that is showing in Xcode before the code even runs.

And just as an explanation, the constraints with 16 are making the width match the width of the white background. And the constraints with the 6 are sizing the dark green background around the UILabel.

EDIT: Adding Full Constraint list

enter image description here

Edit 2: Adding XIB image

enter image description here

1
You have pinned the label to TOP and BOTTOM of view. Hence, the label is doing the right thing by adjusting its height according to the view. If you want to make the label adjust its height automatically, then you need different set of constraints. - Harsh
That UIView's height and width isn't set (the dark green UIView). Its size is solely determined by the size of the UILabel + 6. - Jason Brady
Can you show us all the constraints which you have added. - Harsh
Harsh: I added the full list - Jason Brady

1 Answers

1
votes

Try removing the constraints to bottom and let the UILabel to decide the height for you.

With UILabel you can't have a vertical alignment to top, this answer could help you to understand: https://stackoverflow.com/a/1054681/5109911