1
votes

Did iOS 11 change the content hugging and compression resistance APIs, compared to iOS 10? Here's a setup I had that worked on iOS 10:

Label 1 title is short and Label 2 creates extra width to fill up the space.

[[Label 1][Label 2-------------]]

Label 1 title is long and Label 2 shrinks (but does not truncate!) to make space for Label 1.

[[Very long label t...][Label 2]]

The only constraints I used for this were leading and trailing. No widths, and nothing fancy going on there. The way it worked was Label 1 had a content hugging priority of 251, compared to Label 2's 250. This gave Label 2 the "create extra width to fill up space" ability.

Then, Label 1 had a compression resistance priority of 750, compared to Label 2's 751. This helped make sure Label 2 wouldn't truncate when it shrank.

On iOS 11, this stopped working. Sometimes Label 1 truncates prematurely:

[[Label Titl...][Label 2-------]]

I'm assuming that there's something wrong I'm doing with hugging and compression in the first place. Otherwise, maybe iOS 11 changed something? Or last option, iOS 11 introduced a bug.

1

1 Answers

0
votes

Yes, I have observed the same thing. I were having UITableViewCell, where such 2 labels are there and it is truncating it wrong manner after iOS 11 update. I have solved it by adding following line of code at end of cellForRowAtIndexPath method.

cell?.layoutIfNeeded();

This line works like a charm, as it updates the contstraints for your cell once again.