Your "#define
" Macro:
#define IS_RETINA ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0))
defines some code that executes at run time, not at compile time.
Instead of doing:
#if __IS_RETINA == 1
#define kBorderWidth .5
#else
#define kBorderWidth 1
#endif
You should be setting a run time variable, such as:
static CGFloat gBorderWidth; // at the top of your .m file
or a property:
@property (readwrite) CGFloat borderWidth;
And then set it in your viewDidLoad or viewWillAppear methods:
if(([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0)))
{
self.borderWidth = 0.5f;
} else {
self.borderWidth = 1.0f;
}
Now that I realize you want to make this available to a number of view controllers (e.g. because it was originally in "constants.h
"), why not create a decorator singleton class, which is always in existence for the life of your app and can control the appearance of your app via exposed properties, such as the "borderWidth
" one.
So you could access it via something like:
AppearanceUtilityClass *appearance = [AppearanceUtilityClass sharedInstance];
CGFloat borderWidth = appearance.borderWidth;