When I first started working on TenPair I knew that I should also do something about game UI themes support. But I did not have clear idea how to approach it at that time. This resulted in following monstrosity:
Well… At least colors were not hardcoded… But it wasn’t also much better. Dirty singletons everywhere… And I never got to how theme changes should be handled.
With the latest update to TenPair I wished to add at least one additional color theme. And as it was period for rethinking SpriteKitUI, it was time to address theming.
UIKit has a nice way to set elements appearance app wide. For example setting navigation bar color:
Set once and forget. I wished to use similar pattern.
First step for identifying elements that can be themed was to introduce theming protocol
Appearance defines a bag of properties for every UI element based on full class name. Appearance.Attribute is user defined property key that will be used when theme is applied.
Sample usage for defining app wide View colors:
During theming phase elements will receive defined properties with attribute keys:
When ever colors need to be changed, you will need to perform appearance calls with new values and call applyTheme() on game object
Overall this allowed clear separation of theme definition form game logic and UI. If I only had more theme ideas…
Tags: ios, spritekit