Reputation: 258
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.
Upvotes: 0
Views: 766
Reputation: 67
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.
Upvotes: 0
Reputation: 8322
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)
}
Upvotes: 1
Reputation: 23053
You can use font size variation - define size to font in Storyboard, look in below image it shows how to define size to font.
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.
Upvotes: 1