Set a different font size for iPhone 5 and 6

I searched, but have not yet found an answer.

I would like to set different font sizes for shortcuts for iPhone 5 and 6. I know that I can set a specific layout for Compact Width, but 5 and 6 belong to this group. Is there any way to do this?

+2
ios objective-c iphone resize font-size
source share
3 answers
if UIScreen.mainScreen().bounds.size.height == 480 { // iPhone 4 label.font = label.font.fontWithSize(20) } else if UIScreen.mainScreen().bounds.size.height == 568 { // IPhone 5 label.font = label.font.fontWithSize(20) } else if UIScreen.mainScreen().bounds.size.width == 375 { // iPhone 6 label.font = label.font.fontWithSize(20) } else if UIScreen.mainScreen().bounds.size.width == 414 { // iPhone 6+ label.font = label.font.fontWithSize(20) } else if UIScreen.mainScreen().bounds.size.width == 768 { // iPad label.font = label.font.fontWithSize(20) } 

Or you can get the device using the Apple API and follow the rest of the logic to set the font size. Please contact

+2
source share

You can get an iPhone model and compare it with iPhone5, 5s, 5c, 6 and set the font accordingly. You do not have to use hardcoded dimensions to get a model of the device, but you can get it using the Apple API. Please contact and.

+1
source share

My helper extension:

 extension UIFont { static var sizeMultiplier: CGFloat { return UIDevice.current.isPhone5 ? 0.85 : 1 } static func regular(_ size: CGFloat) -> UIFont { return UIFont(name: "SFUIText-Regular", size: size * sizeMultiplier)! } static func bold(_ size: CGFloat) -> UIFont { return UIFont(name: "SFUIText-Bold", size: size * sizeMultiplier)! } } 

Using:

 titleLabel.font = .bold(16) 

I am also looking for a solution to incorporate iPhone5 size in runtime attributes.

+1
source share

All Articles