0
votes

I struggled in the past to have UILabel adjustsFontSizeToFitWidth working on multiline labels. I soon have found also here on stackoverflow that

adjustsFontSizeToFitWidth property "is effective only when the numberOfLines property is set to 1".

I remember that this was written in the official documentation. But now I can't find it anymore

I was testing my code on Xcode11 with the accessibility inspector to find out labels that needed to be embedded in scroll views. I found out a label that was showing a adjustsFontSizeToFitWidth behaviour even if it was displaying a multiline text. I inspected the "issue", and I have found out that I had this kind of configuration:

Dynamic font type, numberOfLines 0, adjustsFontSizeToFitWidth, lineBreakMode NSLineBreakByTruncatingTail

With this configuration using the maximum font size on the accessibility inspector I don't have this expected result (1): Standard multiline UILabel with adjustsFontSizeToFitWidth not working

But I instead have this (2): A multiline UILabel with adjustsFontSizeToFitWidth perfectly working

It is possible to switch back to what was my expected result changing the lineBreakMode from NSLineBreakByTruncatingTail to NSLineBreakByWordWrapping (the standard setup I was using in my project)

Was I missing something? Was I wrong in expecting (1) from a multiline label with fixed width and height and adjustsFontSizeToFitWidth set to true? Is the behaviour (2) reliable, can I count on it? I can't understand it from the official documentation.

1

1 Answers

0
votes

You need to only set minimumScaleFactor/minimumFontSize to be the same font size as normal(usually its half of the label font size by default) to get the expected result.