3

I have a label, in which is a main feature of the content. I therefore have it set to autoshrink.

The problem is that when I run it on some of the smaller devices, the text is shifted downwards horrendously based on the label box.

How do I fix this?

enter image description here

Edit: This shows the problem that the labels do not fill the container after fixing the autoshrink shifting problem

enter image description here

D-A UK
  • 1,084
  • 2
  • 11
  • 24

2 Answers2

4

Your main issue is that your number of lines for those UILabels is fixed, and you need numberOfLines = 0 to allow that UILabel frame size grow as it needs to, using UITableViewAutomaticDimension in your Cell

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
  • This is misleading. Setting `numberOfLines` to 0 will *prevent* autoshrink entirely. – Grant Palmer Feb 25 '19 at 22:44
  • @GrantPalmer you are right i was thinking that the OP wants to grow the cell instead of shrink the Label that's why – Reinier Melian Feb 26 '19 at 07:10
  • This answer certainly helped me. I have constraints controlling the label size, and Autoshrink set to 'Minimum Font Scale'. Curiously, setting the number of Lines to any number *other* than 1 works—0, 2, 3, whatever. As long as it's *not* 1, the font scales down to fit the label size. How odd! – Kal Jun 25 '19 at 03:23
3

For auto shrink in Storyboard attribute inspector

A. Select Automatic Adjust Font enter image description here

B. Change Auto shrink to minimum font scale/size. enter image description here

NOTE: In some case try to test with line breaking mode to get working state.

Abhishek Thapliyal
  • 3,497
  • 6
  • 30
  • 69