简体   繁体   中英

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: 故事板

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.

模拟器

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

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. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM