Is it now possible to have Multiline UILabel with adjustsFontSizeToFitWidth?

只谈情不闲聊 提交于 2020-01-25 08:53:10

问题


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:

With this configuration using the maximum font size on the accessibility inspector I don't have this expected result (1):

But I instead have this (2):

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:


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.



来源:https://stackoverflow.com/questions/58566616/is-it-now-possible-to-have-multiline-uilabel-with-adjustsfontsizetofitwidth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!