5

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

chakshu
  • 1,372
  • 2
  • 10
  • 21

2 Answers2

2

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.

Community
  • 1
  • 1
Munahil
  • 2,381
  • 1
  • 14
  • 24
  • 1
    Thanks So there is no solution with Storyboard. Frankly if I have to use if conditions for different Devices So why I used autolayout or size classes. – chakshu Aug 06 '15 at 08:04
  • Because as I said, Autolayouts are used so we can use same storyboard for all devices, so they don't target specific devices – Munahil Aug 06 '15 at 08:08
0

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.
Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70