IOS / Swift - How to adjust font size and margin size for each devices screen sizes with autolayout
Asked Answered
C

0

6

Coming from the Android world, I'm trying to create my first IOS app in swift. Actually stuck to build interfaces that are adpative to all screen sizes from Iphone 5s to Ipad 12.9". Autolayout works well except that I can't find how to easily adjust font size and margins for each screen sizes. Maybe I've missed or miss-understood something in my research but my question is : How can I have big margins/font sizes on big screens and smaller margins/font sizes on smaller screens ? Is it possible to have like a constant for a margin for each device or range of screen size in one place so I can easily change it ?

Update : I forgot to mention that I also tried variations on constraints and font size but theres just a few options between "regular" and "compact" and if you need to change a margin you have to change it on all your elements it's seems crazy..

In Android there's a dimension xml file by each screen size/resolution you want where you can have contants and assign them to each element you want. I can't figure out the logic behind IOS here

Thanks in advance

Calida answered 10/1, 2017 at 1:35 Comment(5)
Major up vote on this. What I do? Really bad, I know... I need all the space I can for iPhone SE so my minimum font size is 10 (I believe 1 point under what Apple recommends) and based on the screen's bounds (and orientation) move it up to 15. Not a good thing to do. Margins are accomplished by auto layout, size classes, and traits. A parameter of pretty much all layout constraints is constant and multiplier. As it sounds like you already know, these impact layout - not font size.Dowel
set your label's auto layouts properly and do this label.adjustsFontSizeToFitWidth = true, see whether it helpsTribade
Yes I already tried that but there's nothing to adjust since I have enough width to display a big font size. Like when I center a title horizontally and add a top space constraint. But maybe my constraints are wrong..?Calida
@AbelHamilton did you get right solutions? I am still searchingScale
Unfortunately no.. I end up using variations on constraints trying to find a compromise between each resolutions.Calida

© 2022 - 2024 — McMap. All rights reserved.