Sneha Sneha - 6 months ago 11
iOS Question

Customizable Theme Colour to design Application in ios

I need to make

Application Design
that can be
Customisable
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
ThemeColor
to
Green
instead of Blue then where ever i have used the
ThemeColor
, then it should be done
Green
instead.

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

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,

-(void)viewWillAppear:(BOOL)animated{

NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];

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

UIColor *themeBackGroundColor = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];

self.view.backgroundColor = themeBackGroundColor;

}

hope this will help :)