iphone app xml based theming
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
<navig开发者_Python百科ationbar>
<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?
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
精彩评论