3

I need to make Application Design that can be customizable according to User's wanted Theme.

I should only change colour at one place only and 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..

Kara
  • 6,115
  • 16
  • 50
  • 57
Sneha
  • 880
  • 9
  • 24
  • 1
    I think an easier way to go about this is to create your color palettes as class methods on a UIColor category. That way you can reference it in all places. But change it in one place and expect the reflection. – Vijay Tholpadi Apr 29 '16 at 04:48

4 Answers4

1

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 :)

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Nice solution But using this method, I ll have to initialise all the views to just change it's colors. (event if i dont want any other usages like just lines etc.) Is there any Other Solutions ? – Sneha Apr 29 '16 at 05:14
  • No you not need to initialize every VC, when you open any VC it will set it color. means when it is needed to open VC it will set background color from `defaults` – Ketan Parmar Apr 29 '16 at 05:25
  • you not need to reload every VC when change theme. – Ketan Parmar Apr 29 '16 at 05:25
  • This is Best Answer Thanks @Lion.. Do you know any Way i can set color in storyboard & dont have to set it in code. Then also i can customise it? (might possible using color swatches or palettes or anything like that..) – Sneha Apr 29 '16 at 05:56
  • There is no way to do it like this. If you want to change something dynamically in app you must use code. Imagine how you can change multiple color from storyboard?? storyboard is for initial interface setup(look) of viewcontroller, then you want to change something runtime you must use code. – Ketan Parmar Apr 29 '16 at 06:06
  • you can set initial background color from storyboard but how can change when app running in iphone or device? Imagine it, it's not possible. – Ketan Parmar Apr 29 '16 at 06:07
  • 1
    can you do another favour ? what if i dont want to change at runtime? I want to change before implementing only... I just dont want to change in all VC, just change in color swatches & it changes in all VC in storyboard.. Any thing like that? – Sneha Apr 29 '16 at 06:40
  • No you can't change color in all VC from one place or by one click from storyboard. – Ketan Parmar Apr 29 '16 at 07:16
1

Create a App theme color in your code as follows :

#define APPTHEME_COLOR  [UIColor colorWithRed:238.0/255.0 green:82.0/255.0 blue:87.0/255.0 alpha:1.0]

Use this Theme Color in all controls wherever you require. Once you change this RGB value, your Theme will get changed.

One more thing to say, you don't need to set colors in Storyboard. You have to set it in Code everywhere.

Hope it helps..

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22
  • is there anyway i can set color in storyboard & dont have to set it in code. Then also i can customise it? (might possible using color swatches or palettes or anything like that..) – Sneha Apr 29 '16 at 05:46
1

If you are developing your project with target iOS 7+ and using default iOS UI objects, you can manage theming by changing tintColor property of UIView and using UIAppearance Protocol.

And Yes, you can change tintColor from storyboard/xib too.

Best tutorial for this: https://www.raywenderlich.com/108766/uiappearance-tutorial

--- UPDATE ---

For all iOS version: How to create Multiple Themes/Skins for iphone apps?

I hope this will help you. :)

Community
  • 1
  • 1
Nitesh Borad
  • 4,583
  • 36
  • 51
0

Use the Global tint colour for this purpose. :)

Surjeet Rajput
  • 1,251
  • 17
  • 24