简体   繁体   中英

Different font size on Different devices in same size class

Hi I am new with the size class. As far I know Apple has given one size class (Compact + Regular) for Portrait iPhone 4s, 5, 6 and 6+. So How can I give different fonts size in these three different devices By storyboard or Any other way to do that. Thanks Happy coding

Autolayout and SizeClasses wouldn't target specific devices, so you will have to set the font sizes programatically. You can use check the size of your device using UIScreen.mainScreen().bounds.size.height and set the size of your font accordingly. This solution will clarify you more.

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

First thing is we cant achieve it on storyboard.

You need to assign different font sizes Manually by using If conditions & checking 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 & if you did it already than just need to put above validations in that class.

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