Different font sizes on different devices of the same size

Hi, I'm new to size class. As far as I know, Apple has provided one size class (Compact + Regular) for Portrait iPhone 4s, 5, 6, and 6+. So, how can I give the size of different fonts in these three different devices by storyboard or any other way to do it. thanks Happy coding

+5
source share
2 answers

Autolayout and SizeClasses will not target specific devices, so you will need to set the font size programmatically. You can use the size of your device with UIScreen.mainScreen().bounds.size.height and set the font size accordingly. This decision will clarify you more.

+2
source

As you mentioned in your question, you need to provide separate font sizes for different devices.

First of all, we cannot achieve this on the storyboard.

You need to assign different font sizes manually using If conditions and validation devices.

For ex:

 if ([[UIScreen mainScreen] bounds].size.height == 568) { // Assign Font size for iPhone 5 }else if ([[UIScreen mainScreen] bounds].size.height == 667){ // Assign Font size for iPhone 6 }else if ([[UIScreen mainScreen] bounds].size.height == 736){ // Assign Font size for iPhone 6+ }else if ([[UIScreen mainScreen] bounds].size.height == 480){ // Assign Font size for iPhone 4s } 

Note:

  • You can create a separate Font class, and if you have done this already, you just need to put above the checks in this class.
0
source

All Articles