我不知道有关最佳做法。但是,如果你的应用程序是不够大,那么一个结构良好的plist是你的朋友。
最初,您可以选择:金属主题。以下内容应该适用:
您可能有一个Singleton ThemeManager
,或者只是将一个NSDictionary
粘贴到您的一个Singleton(如果适用)。
的ThemeManager背后的关键是资产和主题之间的映射..
一些示例代码(直接写SOF ..不要介意语法错误):
#define kThemeMap(__x__) [[ThemeManager sharedManager] assetForCurrentTheme:__x__]
...
-(void)doUselessStuff {
UIImage* backgroundImage = [UIImage imageNamed:kThemeMap(@"FirstViewBG")];
...
}
//in the ThemeManager:
//returns the appropriate name of the asset based on current theme
-(NSString*)assetForCurrentTheme:(NSString*)asset {
//_currentTheme is an NSDictionary initialized from a plist. Plist can be downloaded, too.
NSString* newAsset = [_currentTheme objectForKey:asset];
if(newAsset == nil) {
newAsset = [_defaultTheme objectForKey:asset];
}
return asset;
}
//Let us assume the user selects Metal Theme somewhere .. Still coding ThemeManager:
-(void)selectedNewTheme:(NSString*)newTheme {
//First, get the full path of the resource .. Either The main bundle, or documents directory or elsewhere..
NSString* fullPath = ...;
self.currentTheme = [NSDictionary dictionaryWithContentsOfFile:fullPath];
}
的的plist文件只是一个字符串字典字符串的映射......是这样的:
//Default.plist
@"FirstViewBG" : @"FirstViewBG_Default.png"
@"SecondViewBG" : @"SecondViewBG_Default.png"
@"WinSound" : @"WinSound_Default.aiff"
//Metal.plist
@"FirstViewBG" : @"FirstViewBG_Metal.png"
@"SecondViewBG" : @"SecondViewBG_Metal.png"
@"WinSound" : @"WinSound_Metal.aiff"
或者,你可以只保存后缀,如果是够用了哟但是,它将需要字符串操作,通过切分扩展名 - >添加后缀 - >添加扩展名。
或者可能使它成为前缀?
这里有一个非常详细的解释如何皮肤的iOS应用程序在这里:http://stackoverflow.com/questions/8919334/how-to-create-multiple-themes-skins-for-iphone-apps?rq= 1它还解释了如何为笔尖蒙皮,尤其是来自iOS 5. –
你可以看看下面的图书馆https://github.com/charithnidarsha/MultiThemeManager –