I created a sample project to reproduce this.
I've a xib file with an UILabel having a fixed top, leading and trailing constraint. I added a minHeight constraint and set the number of lines to 0.
I set the preferredMaxLayoutWidth to Automatic (checked in the xib file).
In viewDidLoad, I've this:
self.myLabel.layer.borderColor = [[UIColor redColor] CGColor]; self.myLabel.layer.borderWidth = 2.0f;
self.myLabel.text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
And when i run the simulator on iPhone 6 or 6+, I get this:
I've no idea where that top and bottom padding is coming from and it's proportional to the amount of characters in the UILabel is showing.
Is there some magic setting I forgot ? It runs fine on iPhone 4" devices.
Now if I don't set the preferredMaxLayoutWidth, it doesn't have the extra padding but this breaks my multi-lines in the UILabel. It cuts off the text. I did not use Size-Class.
Edit:
So I changed few things on my sample project to match the situation on my real project. I've added a tableView (with top, leading, bottom and trailing constraints set to its parent view). Each cell on the tableView has 4 labels. The top label has a top, leading and trailing constraint to the contentView of the cell and the subsequent labels have a vertical constraint to the label above it. Every label has a heightGreaterThan constraint set and a widthGreaterThan set.
This is how it looks like without the preferredMaxLayoutWidth set (Notice how labels are capped to 1 line).
With preferredMaxLayoutWidth. Now the UILabel shows the entire content but has a padding on top and bottom.
Edit2: Sample Project: https://www.dropbox.com/s/sdahx9njnsxiv98/MultiLineUILabel.zip?dl=1
preferredMaxLayoutWidth
by adding a few pixels, but this number is highly dependent on how wide the screen is and renders differently on iPhone 6, iPhone 6+ and iPhone 5. Not to mention iPad. Not sure if it is a bug or if there is some other setting / hack to get it to work. – Michael Gaylord