Adauto Pinheiro
Adauto Pinheiro

Reputation: 81

Best way to resize font sizes for different devices automatically?

So, i have many labels in my app, and like everything, they have auto-layout, and it works great but for the text inside them. The label layouts as expected, but the text inside them gets cut in smaller devices.

To avoid that, i tried using AutoShrink option in interface build, but it got really messed as you can see in the pictures:

iPhone 7 simulation without AutoShrink

iPhone SE simulation without AutoShrink

iPhone SE simulation with AutoShrink

So, as you can see, all labels shrinks differently from each other, resulting in texts with different sizes breaking the App Harmony and design.

What's the best approach to deal with this situation? How can I make that if I need to shrink one label, all of them get shrink to the same size?

Upvotes: 1

Views: 37

Answers (1)

Andrew Romanov
Andrew Romanov

Reputation: 5076

You can use adjustsFontSizeToFitWidth and minimumScaleFactor:

label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5

This creates a text smaller for long strings.

Also you can add more lines for label, using numberOfLines.
I think first solution is better for you.

Upvotes: 1

Related Questions