SJP
SJP

Reputation: 1372

IOS Swift resize label font size when screen size changes

I have multiple labels in the storyboard using the any X any Resolution as follows: Storyboard

Now I have added constraints to the best of my knowledge to force the labels to reposition when an iphone simulator is used and the following happens.

Simulator

What I would like to happen is have the labels remain the same distance apart from each other proportionally and just resize their font size. So If we were to divide the Iphone screen into thirds Days would occupy the first 3rd, months the 2nd, and Years the 3rd. I thought maybe using aspect ratio for constraints would work but I got the same effect of the labels bunching on top of each other. It looks like they maintain the constraint of distance from the edges but they wont resize themselves to keep the ratio.

Thanks

Upvotes: 0

Views: 3328

Answers (1)

Tejvansh
Tejvansh

Reputation: 676

If you want to keep same distance between each of them, one way of achieving it is: Give all of them equal widths constraint. and set leading and trailing constraint to zero. Align all labels to centre horizontally.

This way, you wont need to change the font size.. But, however, if you still want to change font, go to attributed inspector for label and under auto shrink: change fixed font size to minimum font size and set it to appropriate value, say 14. enter image description here

Upvotes: 1

Related Questions