0

I have a multiline UILabel that I'd like to look similar on different devices (iPhone only). If it was a single line, I'd simply place the auto layout constraints and enable Autoshrink and set the Minimum Font Scale.

The height of the label is dynamic is calculated based on text. To do that, I need the font, which should also be dynamic. The hack I could do is place an invisible label, and set the text I want to fit in a single line into it and calculate the font, but it seems too hacky.

Another thing I'm not that familiar with are size classes. But from what I've read, the same class is shared between all portraits, meaning 3.5, 4, 4.7 and 5.5 inch devices would be bound to the same class, therefore I couldn't use the separate font value?

How would I implement the 'font scaling' for multiline labels so I'm getting similar look on different screen sizes?

Darius41
  • 3
  • 2

1 Answers1

0

If by similar look you mean that the same words appear on each line, I don't think it's possible.

If the label height is dynamic based on the amount of text, the label will simply expand to the height required to show the text with the specified font size.

Font scaling only kicks in when there is not enough space to display the text with the specified font size. Therefore, you must constrain the height or number of lines.

I was able to approximate this using a multiline UILabel with font scale of .5. I set an Equal Heights constraint between it and its superview, with a multiplier of .25. See screenshots below.

In this approach, you would have to dynamically change the Equal Heights multiplier based on the amount of text you have.

Mike Taverne
  • 9,156
  • 2
  • 42
  • 58