Search code examples
iphoneglobal-variablesuicoloruibackgroundcolor

How to set global variable with UIColor class


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.


Solution

  • Very simple.
    In AppDelegate.h:

    #define kGlobalColor [UIColor colorWithRed:(238.0f/255.0f) green:(251.0f/255.0f) blue:(255.0f/255.0f) alpha:0.8f]
    

    In ViewControllers:

    #import "AppDelegate.h"
    
    self.view.backgroundColor = kGlobalColor;