How to place text in UILabel if size is not proportional

As for the title, how would I put text in a UILabel if the width and height are not proportional?

In my application, the label has a width of 100, a height of 500, and a font size of 400. The result in the simulator is that the text is out of scope and cannot be fully displayed on the screen. If I have a adjustsFontSizeToFitWidthfont no longer 400, which is a requirement.

I know that if the text is not scaled proportionally, it will look strange, but for me this is not a problem.

+3
source share
1 answer

If you just want the label to be as large as the label should contain, you can set it more than it should in any case, and align it if necessary.

Another variant:

label.text = newText;
CGRect bounds = label.bounds;
bounds.size = [newText sizeWithFont:label.font];
label.bounds = bounds;
+5
source

Source: https://habr.com/ru/post/1707179/


All Articles