Weakman10122
Weakman10122

Reputation: 391

Use a UIImage with text or UILabel for automatically scaled text

I have text that needs to be scaled for each iOS device depending on the screen size. Apparently, you can't scale UILabel font size automatically except manually code wise (unless I am missing something). Instead of having to code for a lot of scenarios, would it be better to use an UIImage that has all the text? This way I can make the text scale automatically depending on device size?

Upvotes: 0

Views: 131

Answers (1)

Lyndsey Scott
Lyndsey Scott

Reputation: 37300

You can make a UILabel's text scale automatically by (1) setting auto layout constraints for that UILabel such that its height and width are relative to the screen size, (2) setting the label's base font to at least the size which it would be on the largest screen, then (3) setting its "auto shrink" property such that its minimum font scale or minimum font size would be at least as small as the font on the smallest screen.

I do not recommend using an UIImage instead because you wouldn't be able to edit or localize it as easily.

Upvotes: 1

Related Questions