Swift 3.0 Dynamically Change Font of a Label

Viewed 771

I am using a label to display text that the user has entered so the length of the label is variable. I am wondering if there is a way to dynamically change the font size of my text. Currently, I have constraint the vertical length of the label to 120, and checked off the "Automatically Adjust Font" in the Attributes Inspector but it doesn't scale it like I want. Not sure whether this is a programmatic or design method to do this.

Here's an example of the text being cut off:

enter image description here

2 Answers

you can try, eg:

autoshrink -> minimum font scale -> 0.7

enter image description here

You can try this below;

yourLabel.numberOfLines = 0;
yourLabel.minimumScaleFactor = 0.7;
yourLabel.adjustsFontSizeToFitWidth = true;
Related