user5036765
user5036765

Reputation: 1

Adjust UILabel size based on size Swift

I'm trying to adjust my label size based on screen size using swift. I'm using the dynamic layout and cannot figure it out. Essentially what I am looking to do is shrink the text/font size to fit within my frame.

Upvotes: 0

Views: 292

Answers (1)

Eric
Eric

Reputation: 2097

You can do this all in the storyboard.

Add constraints between the leading and trailing edges of the label and its superview. (Something like |-[label]-| in the visual format.) This will adjust the width of the label as the width of its superview changes.

If you want the font size to adjust as well, you can set the Autoshrink item in the storyboard to Minimum Font Scale and set an appropriate value (0.5 is the default).

Upvotes: 1

Related Questions