我想在iPhone的应用程序项目中实现主题属性。我在第一级有近5-6种背景颜色,在第二级有3个背景,在主题的变化我想要改变3个图像。
我想控制一个中心位置的所有颜色。
告诉我实现此目的的最佳方法或任何教程或任何示例代码。
提前致谢
答案 0 :(得分:0)
我会创建一个处理此问题的类(最好是单例)。
@interface Themes {
int theme; //or you can create a enum
}
-(UIColor *)colorForBackground; //or any other component
-(UIImage *)backgroundImageForButton; //..
-(NSString *)xibNameForController:(NSString *)controller; //or you can add a enum/define for controllers
@property() int theme; // used to change or get the current theme; You can also send a NSNotification when the theme is changed, so that the content is refreshed
@end
@implementation Themes
@synthesize theme;
-(UIColor *)colorForBackground{
if(theme==0){
return [UIColor whiteColor];
}
if(theme==1){
return [UIColor blueColor];
}
//etc.
}
-(NSString *)xibNameForController:(NSString *)controller{
if([controller isEqualToString:@"MailController"]){
if(theme==0)
return @"MainControllerTheme0";
//...
}
//...
}
//..
@end