0

I have button called login. when i see the button font size it looks same in all the devices, though the button width and height vary. How to define different font size for different devices?. I am talking about only for iPhone portrait. So don't give solution as size class.

John
  • 238
  • 2
  • 11
  • you can use size classes for this . – KKRocks Apr 19 '17 at 11:25
  • 1
    Possible duplicate of [iOS Different Font Sizes within Single Size Class for Different Devices](http://stackoverflow.com/questions/28076020/ios-different-font-sizes-within-single-size-class-for-different-devices) – KKRocks Apr 19 '17 at 11:26

3 Answers3

1

You can use font size variation - define size to font in Storyboard, look in below image it shows how to define size to font.

enter image description here

Click on small + button besides Font property, a pop up will appear.

As shown in above image you can define size for Width and Height for different variation.

Kampai
  • 22,848
  • 21
  • 95
  • 95
1

Try this

if UIScreen.mainScreen().bounds.size.height == 480 {
    // iPhone 4
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)     
} else if UIScreen.mainScreen().bounds.size.height == 568 {
    // IPhone 5
    mybutton.titleLabel.fontt = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 375 {
    // iPhone 6
   mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 414 {
    // iPhone 6+
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 768 {
    // iPad
    mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84
0

You can check the iPhone device size and then in if-else loop apply your button font size logic.

#define iPhoneVersion ([[UIScreen mainScreen] bounds].size.height == 568 ? 5 : ([[UIScreen mainScreen] bounds].size.height == 480 ? 4 : ([[UIScreen mainScreen] bounds].size.height == 667 ? 6 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 7 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61   : (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 10 :61 )))))))

if (iPhoneVersion == 4)
{
    mybutton.titleLabel.font = [UIFont systemFontOfSize:12];
}
else if (iPhoneVersion == 5)
{
    mybutton.titleLabel.font = [UIFont systemFontOfSize:14]; 
}
else if (iPhoneVersion == 6)
{
    mybutton.titleLabel.font = [UIFont systemFontOfSize:16]; 
}
else if (iPhoneVersion == 7)
{
    mybutton.titleLabel.font = [UIFont systemFontOfSize:17]; 
}

and same goes for all devices.

mini coder
  • 57
  • 1
  • 9