Sneha Sneha - 1 year ago 46
iOS Question

Customizable Theme Colour to design Application in ios

I need to make

Application Design
that can be
according to User's wanted Theme.

I should only change colour at
one place
only &
whole application theme
should be changed.

NOTE: Different Theme Contains Different Theme Colours..

What i have did is Make a
colour palette
like this..

Set ThemeColors Named Colour Palette

In this image, if i change
instead of Blue then where ever i have used the
, then it should be done

But I can't able find a way to
customise this colours
. Or any other way, i am missing out to achieve my requirement..???

Any help appreciated.. Thanks in Advanced.

Answer Source

You should use NSUserDefault to store current theme. In your every ViewController set background color from NSuserdefault from viewwillAppear or viewDidAppear because it will calls everytime when you navigate back also. when change theme change the color in userdefault so your every viewcontroller will get that color.

Update as asked in comment :

you can store color like this,

 NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];

UIColor  *currentThemeColor = [UIColor redColor]; //any color instead of red which user change from settingviewcontroller

NSData *colorData =  [NSKeyedArchiver archivedDataWithRootObject:currentThemeColor];

[myDefaults setObject:colorData forKey:@"themeColor"];

and then from every view controller,


NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];

NSData *colorData = [myDefaults objectForKey:@"themeColor"];

UIColor *themeBackGroundColor = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];

self.view.backgroundColor = themeBackGroundColor;


hope this will help :)