i am developing on iPhone application. in this app i have 4 different views. in all views i set background color. see bellow code
self.view.backgroundColor = [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f];
i am testing various colors for background color. when i have to change any colour i need to change in all view controllers. instead of that can i make global variable for this ? i don't know how to set UIColor in global variable. please suggest me some ideas.
create
constant.h
file ofNSObject
and define this color globally#define globalColor [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f];
and when you want to use it just import the constant file other wise 2 option is bellow..
Second Option
in
AppDelegate.h
file just property synthesize one variable of UIColor like bellow..and synthesize in .m file like bellow..
and in
didFinishLaunchingWithOptions
method just asssign color to this variable..and when you want to use this color use like this..
Better than using a global variable is to extend
UIColor
. Make a category with a constructor, that provides your color:UIColor+mycolor.h:
UIColor+mycolor.m:
Very simple.
In AppDelegate.h:
In ViewControllers: