In my case I have a highly customized iPhone app with all custom views. I’d like to take advantage of the iPhone 5 screen size, but my views require precise layout, and setting the autoresizingMask on my views is not sufficient.
I’d like to end up with some sort of project wide definition flag in each of my source files, and I would need to set this definition/flag at runtime. In my specific case, I could perhaps import some header file definition like this:
if ( IS_IPHONE_5 ) {
/*
Set appropriate frames for the additional screen space
*/
}
else {
/*
Set views otherwise
*/
}
This question isn’t intended to be entirely subjective–it could apply to anyone looking to set and retrieve project wide definitions. Perhaps another case could be a color theme or something that could be changed in settings.
How do I set these definitions while my program is executing and how do I incorporate them across my source files?
Thank you.
It could be as simple as putting a macro into your app’s
APPNAME_prefix.pchfile:Every file in your application would be able to use it.
As an alternative suggestion, I think my preference would be to add a category on
UIDevice, and perhaps also add a macro for convenience, and then have only the objects that needed it (i.e. objects in the view and controller layers responsible for layout) import it, to avoid coupling your model toUIKit.For example,
UIDevice+iPhone5.h:and
UIDevice+iPhone5.m:Whichever best suits your needs. Hope this helps!