views:

21

answers:

1

I am creating theme for my app that is xml based and will be stored in a themes folder of my app. I need to traverse that file and apply theme i.e. set navigation bar styles, tabbar styles, fonts etc. What might be best possible solution for doing this? i have got about 7-8 viewcontrollers that needs to be applied that theme on app launch or viewdidload method. Any suggestion would be great.

I have created xml parser that converts any xml to NSMutableDictionary. Each node is identified by following class

@interface xmlObject : NSObject {
 NSString *innerText;
 NSMutableDictionary *children;
 NSString *NodeName;
 NSDictionary *attributes; 
}

so xml with structure

<navigationbar>
   <backgroundcolor> <!-- rgb with values between 0-1 -->
    <red>0.8</red>
    <green>1.0</green>
    <blue>0.5</blue>
    <alpha>0.8</alpha>
   </backgroundcolor>
   <tintcolor> <!-- rgb with values between 0-1 -->
    <red>0.8</red>
    <green>1.0</green>
    <blue>0.5</blue>
    <alpha>0.8</alpha>
   </tintcolor>
   <backgroundimage></backgroundimage>   <!-- png 320 * 44 -->
   <color> <!-- rgb with values between 0-1 -->
    <red>0.8</red>
    <green>1.0</green>
    <blue>0.5</blue>
    <alpha>0.8</alpha>
   </color>
  </navigationbar>

will have navigation bar as a key of NMUTAble Dictionary object returned by xmlOBject method say parsexml and will have 4 children nodes each itself a NSMUtableDictionary. So if I want to access backgroundimage node then following code get its value

[[[[tmp objectForKey:@"navigationbar"] objectForKey:@"children"] objectForKey:@"backgroundimage"] objectForKey:@"innertext"]

// where tmp is the NSMutableDictionary returned byxml obj instance method.

What might be best possible soluion to parse xml that contains style for each screen like the one i showed for navigationbar?

+2  A: 

I did something similar. I created a ThemeManager object wich handles loading of a plist flie containing data like these :

<key>MainWindow</key> 
<dict>
<key>BackgroundImage</key>
<string>background.jpg</string>
<key>TextColor</key>
<string>1,1,1,1</string>            
</dict>
...

Then is your app you just have to get value using KVC. For exemple I am loading image then display it in nackground.

backgoundImage.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", self.appDelegate.themesManager.assetsPathDocumentsFolder, [self.appDelegate.themesManager getElementValueAtKeyPath:@"MainWindow.BackgroundImage"]]];

Hope this helps.

Thierry

thierryb
Thanks for the reply. i am trying to avoid plist since i am already parsing xml to NSMutableDictionary. What might be the design of such application. Should I create drawrect methods of Navigationbar, and toolbar and tabbar and apply theme there or should I do it on viewdidload method. I got all the style in an NSMutableDictionary.
Ayaz Alavi