【问题标题】:How to make theme based iPhone Application?如何制作基于主题的 iPhone 应用程序?
【发布时间】:2011-11-05 20:58:19
【问题描述】:

我想在 iPhone 的应用程序项目中实现主题属性。我在第一级有大约 5-6 种背景颜色,在第二级和 3 级图像有 1 个背景颜色,我想根据主题的变化进行更改。

我想从一个中心位置控制所有颜色。

告诉我实现这个目标的最佳方法或任何教程或任何示例代码。

提前致谢

【问题讨论】:

标签: iphone themes background-color


【解决方案1】:

我会创建一个类(最好是单例)来处理这个问题。

@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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多