0

I have five ui labels for one view. All of them have variable text content. To prevent truncating I have to use Autoshrink text size. My ui labels are aligned in x axis top to bottom. The problem is; when autoshrinking, all ui labels have different font sizes. Is there a way to equalize font sizes of all ui labels when autoshrink. I use interface builder autolayout constraints. Thank you.

Gocas
  • 1
  • try `label.numberOfLines = 0` for your all labels. and dont give view height constraint. Every label must have top and bottom constraint. – dahiya_boy Sep 06 '18 at 11:44
  • 1
    Possible duplicate of [AutoLayout link two UILabels to have the same font size](https://stackoverflow.com/questions/20262156/autolayout-link-two-uilabels-to-have-the-same-font-size) – Rengers Sep 06 '18 at 11:46
  • @Rengers i guess that solution is pretty outdated. Not working for me – Gocas Sep 06 '18 at 16:19

1 Answers1

0

You could loop through your labels, find the smallest text size and then set that text size to all of them. That way, you know they'll all fit and have the same text size. You would have to do this programmatically. Alternatively, you could dynamically change the size of your UILabels based on the number of characters it holds times some constant factor. That way, the autoshrink should set the same size for each the text in each of the labels.

AOgren
  • 1
  • In that case, I cannot use the optimum font size. All labels become too small. I tried to run a for loop to get the optimum font size without violating the constraints but I could not get the font sizes after autolayout applies. Even viewwillappear did nor work to get adjusted font sizes. Do you have a comment on that? Thanks. – Gocas Sep 07 '18 at 20:12
  • Perhaps you could query for the width of the screen and then scale each UILabel based on the number of characters that are in the text of the UILabel. For example, if the width of the screen is 100 pixels and you have 3 labels with text "go", "the", and "calls" respectively. Then label 1 should have width of 20px, label 2 should have width of 30px, and label 3 should have width of 50px. Then the autoshrinking should handle the size of the text. @Gocas – AOgren Sep 08 '18 at 21:14