我想在我的iPhone应用程序项目中实现主题属性。我有大约5-6个背景颜色在第一级和1多个背景在第二级和第三级的图像,我想改变主题的变化。
我想从一个中心位置控制所有的颜色。
告诉我实现本教程或任何教程的最佳方式,或者任何示例代码。
提前感谢
发布于 2011-11-05 20:58:19
我会创建一个类(最好是单例)来处理这个问题。
@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
https://stackoverflow.com/questions/8019972
复制相似问题