问题
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.
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..
回答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. :)
回答2:
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..
回答3:
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 :)
回答4:
Use the Global tint colour for this purpose. :)
来源:https://stackoverflow.com/questions/36929667/customizable-theme-colour-to-design-application-in-ios