jeudi 26 février 2015

How should I handle different font sizes on the iPhone 5S and 6 Plus?

We are using a font size of 12pt for the 5S, but that is tiny and unreadable on the 6 Plus. So we need to bump up our font size to 15pt on the 6 Plus, but then our padding and margins are all messed up, since we are using some hard-coded offsets in our auto-layout constraints.


I experimented with removing the 6 and 6 plus launch images to force a "zoom", but that's not ideal. We actually do want some of our content to be smaller, to take advantage of the higher resolution.


I was just wondering what other iOS developers are doing? Do you set up dynamic font sizes and padding?


I've just written this little helper file in Swift, but not sure if it's the best way of doing things:



let DEVICE_WIDTH_5S: CGFloat = 320.0 // 320x568
let DEVICE_WIDTH_6: CGFloat = 375.0 // 375x667
let DEVICE_WIDTH_6PLUS: CGFloat = 414.0 // 414x736

let screenSize: CGRect = UIScreen.mainScreen().bounds

// Helper functions for fonts
func ProximaNova(style: String, size: CGFloat) -> UIFont {
return dynamicFont("ProximaNova", style, size)
}
func BrandonGrotesque(style: String, size: CGFloat) -> UIFont {
return dynamicFont("BrandonGrotesque", style, size)
}

private func dynamicFont(name: String, style: String, size: CGFloat) -> UIFont {
var dynamicSize = size

// Increase our font size for iPhone 6, 6+ and above
if screenSize.width >= DEVICE_WIDTH_6PLUS {
dynamicSize += 3.0
} else if screenSize.width >= DEVICE_WIDTH_6 {
dynamicSize += 2.0
}

return UIFont(name: "\(name)-\(style)", size: dynamicSize)!
}



Aucun commentaire:

Enregistrer un commentaire