vendredi 11 décembre 2015

Global variables/singleton alternatives for storing dependent сonstants

I'm developing a game and want to create a config for easy app skinning.

I'm stuck with device specific constants. For example I want to store device-specific font size. Lets say I want 30 for iPhone and 45 for iPad. Now I do it by declaring global variable like so:

let h2FontSize : CGFloat = UIDevice.currentDevice().userInterfaceIdiom == .Pad ? 45 : 30

Then use it like so:

private let topLabel = CCLabelTTF(string: "", fontName: mainFontName, fontSize: h2FontSize)

But that is not seem like a beautiful solution, because I also have h1, h3 fontSize and they all look the same.

How to deal with device-specific constants?

Aucun commentaire:

Enregistrer un commentaire