How to make text labels scale font size on different screens of Apple products?

This is for ios dev with fast. I have a very simplified layout:

link1 (not enough rep to post pic)

All I'm trying to do is make sure that the “results” label scales approximately the same for every different screen size. As you can see below, the difference between the 3.5 screen and the iPad screen is extremely noticeable:

link2

So, I want to make the shortcut on the iPad screen big enough to tackle the same percentage of space as on the 3.5 screen, both vertically and horizontally. How can I do it? I went through several other tutorials / solutions, but they all teach you something else, how to change the label size, but not the font size. I tried to add an aspect ratio constraint, but that only shifts it without changing the font size. Adding a height and width limit also resizes the label without font size.

+5
source share
2 answers

In fact, you can do this in your storyboard.

1, open the “File inspector” tab (first tab) on the storyboard, check the boxes Use auto layout and Use size classes .

2. Then you can go to the tag attribute (Forth tab), you will notice that there is a “+” next to it, click it to add it.

3, select the screen size u want like, you can link "Adaptivity and Layout" , and then select the font size.

Answer THIS LINK , you can also look

+3
source

Hyung

Here is a super message about detecting device / screen size.

How to detect iPhone 5 (widescreen devices)?

This is my favorite suggestion, click on it and thank the real author!

Add new Swift file -> AppDelegateEx.swift

add extension to AppDelegate

 import UIKit extension AppDelegate { class func isIPhone5 () -> Bool{ return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 568.0 } class func isIPhone6 () -> Bool { return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 667.0 } class func isIPhone6Plus () -> Bool { return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 736.0 } } 

using:

 if AppDelegate.isIPhone5() { collectionViewTopConstraint.constant = 2 }else if AppDelegate.isIPhone6() { collectionViewTopConstraint.constant = 20 } 

Combine it with the font settings in your application, which you probably should be doing right now?

 variable.font = UIFont(name: "Palatino", size: 24) 
+5
source

Source: https://habr.com/ru/post/1243909/


All Articles