SwiftTheme

As part of our project requirement, we need to add night mode to our app. It’s not as simple as just changing brightness or alpha on the top-level view—in fact, it needs an entirely new interface: different colors, different alpha, different image cuts. More accurately, “night mode” is a theme/skinning feature that can switch between bright theme and dark themes.

So how do we achieve this? Maybe we can set a global variable that represents the currently selected theme, and use different background colors or image cuts based on the variable during the controller’s initialization. But then how do we deal with views that have already been initialized? Yes, we could use notifications to change their colors or image cuts, but this leads to controllers unnecessarily full of notification register/unregister, if…else and UI updating code. Worse, if you forget to unregister the notifications, your app may crash.

After some consideration, we put forward higher requirements on the task: create a simple and reusable themes/skinning framework, here as you see.

Goals

Make SwiftTheme a simple, powerful, high-performance, extensible themes/skinning framework. Provide a unified solution for iOS.

Features:

  •  Written in Swift
  •  Fully compatible with Objective-C
  •  Based on runtime
  •  Simple integration
  •  Extension property prefix with “theme_*”, friendly with IDE auto-completion
  •  Support UIAppearance
  •  Index mode, fast integration
  •  Plist mode, extend infinite themes
  •  Friendly error logs
  •  Strongly typed ThemePicker, detect errors during compilling
  •  Complete demos

Posted

in

,

by

Tags:

Comments

Leave a Reply