Ignacio Oroná
Ignacio Oroná

Reputation: 4399

iOS/Objective-C Design Pattern for UI Themes

I need to write a iOS Objective-C app that supports Themes. The idea is that through some configuration control panel, the user is able to select one of the three hypothetical themes {redTheme, greenTheme or blackTheme} that are predefined in my app, according to the following schema:

1theme http://www.timotteo.com.ar/ThemeChart.png

The user could also even choose the new theme while he is seing the view, and the view would automatically redraw (although this is not a fundamental feature). I would also expect to have a basic theme, (for example whiteTheme). The themes would customize not only the background colors of the view, but they would also customize the images of the UIButtons, UISliders, etc. My question is: is there a design pattern that would help me solve this problem? Or at least some OOP concept? Any direction is appreciated. Txs in advance

Upvotes: 4

Views: 2530

Answers (3)

Boobalan
Boobalan

Reputation: 823

UIAppearance framework makes this job easier for navigation bar and UIControl objects

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAppearance_Protocol/index.html

Upvotes: 0

Bo.
Bo.

Reputation: 2541

Well from the nice diagram you prepared it looks a lot like Strategy Pattern (or any number of similar patterns). See more at: http://en.wikipedia.org/wiki/Strategy_pattern

Kind regards,
Bo

Upvotes: 2

user529758
user529758

Reputation:

Basically, you can consider the approach WinterBoard uses for theming. Make your UI element image names unified (for example, buttonBackground.png, statusBar.png, etc.) and store the non-image (pure color) information in a PLIST file, with keys for each UI control, something like

<plist>
<dict>
    <key>ButtonBackgroundColor</key>
    <string>#00ff00</string>
    <key>LabelBackgroundColor</key>
    <string>#007fcc</string>
</dict>
</plist>

et cetera. Then, make your themes according to this pattern, use the same image names / color keys in your app for loading the UI data, but based on the current settings (which is presumably stored in NSUserDefaults), load the resource files from a different directory.

I hope this will be helpful.

Upvotes: 2

Related Questions