Tak*_*aka 7 iphone themes skin ios
我想让我的iPhone应用程序能够在皮肤之间切换(或设计主题,或外观和感觉,如木头,金属,地球颜色,男人,女孩等......).
我将准备一些包含按钮和背景,声音和文本颜色图像的皮肤集,并让用户通过应用程序设置决定他们想要使用哪一组皮肤.
实现这个的最佳做法是什么?
条件是:
我正在考虑在我的应用程序中创建所有UIViewControllers的超类并覆盖它加载Nib文件的部分,而不是从主bundle加载,从Document目录中保存的皮肤加载资源...但我不知道怎么做... Nib加载方法的默认行为总是从主包加载资源,阅读后会丢失有关资源文件名的信息.... :(
在此先感谢您的帮助.
我不确定最佳实践。但是,如果您的应用程序不够大,那么结构良好的 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];
}
Run Code Online (Sandbox Code Playgroud)
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"
Run Code Online (Sandbox Code Playgroud)
或者,您可以只保存后缀,如果这对您来说足够好的话。但是,它将需要字符串操作,通过切片扩展名 - >添加后缀 - >添加扩展名..
或者也许将其作为前缀?
| 归档时间: |
|
| 查看次数: |
7673 次 |
| 最近记录: |