Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Am not sure about best practice .. But, if your app is not big enough, then a well structured plist is your friend.</p> <p>Initially, you could choose: Metal Theme. The following should hold:</p> <p>You either have a Singleton <code>ThemeManager</code>, or just stick an <code>NSDictionary</code> to one of your Singletons if appropriate.</p> <p>The point behind the ThemeManager is the mapping between the asset and the theme..</p> <p>Some sample code (written directly on SOF .. Don't mind Syntax mistakes):</p> <pre><code>#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]; } </code></pre> <p>The plist files are just a dictionary with string to string mapping... something like this:</p> <pre><code>//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" </code></pre> <p>Alternatively, you can just save the postfix, if that is good enough for you.. But, it will require string manipulation, by slicing the extension -> adding the postfix -> adding the extension ..</p> <p>Or maybe make it a prefix?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload