- Notifications
You must be signed in to change notification settings - Fork0
Easy to use and lightweight theme manager for iOS applications written in Swift with UIKit, but taking advantages of Objective-C reflection capabilities.
License
wupdigital/SuitUp
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Easy to use and lightweight theme manager for iOS applications written in Swift with UIKit, but taking advantages of Objective-C reflection capabilities.
Repository also contains an Example app, which helps you to define themes and styles in a protocol oriented way.
Just openSuitUp workspace
and have fun!
UseCocoaPods:
pod'SuitUp'
or you can install manually:
Download it, then drag and drop the contents ofSuitUp/SuitUp
folder into your project.
Of course don't miss to importSuitUp where you want to use.
import SuitUp
A theme contains color, font and image definitions based on the design, but you can extend it with anything you need.InSuitUp you can change between these themes, like the usual light and dark modes.
The base theme contains these types of attributes, but you can extend it if you derive a protocol and use this extended one everywhere in your project.In the example project you can see a color palette like the following:
protocolColorPalette:Colors{varprimary:UIColor{get}varsecondary:UIColor{get}vartertiary:UIColor{get}varprimaryText:UIColor{get}varsecondaryText:UIColor{get}}
After you successfully created your themes, you have to register them during application launch insidedidFinishLaunchingWithOptions:
inAppDelegate
.
SuitUp.shared.registerThemes(SunriseTheme(),SunsetTheme())SuitUp.shared.logLevel=.warning
and you can set the log level to warning or info based on your preferences. My suggestion is info level in the beginning, because you will see more information about style settings under the hood if you choose this level.
You can change currently used theme in runtime withchangeTheme(to:)
function inSuitUp.
Each style contains stylable properties mirrored from the UI component, that you want to style. However styles live completely independent from UI components, so you never have to extend your UI components with anySuitUp related code snippets.You can define these properties in a descriptor, which you can read about in the next section.So ifUIView
has abackgroundColor
property and you want to style it throughSuitUp, you have to add this property to the style. It works with any property, but only if the property is accessible from Objective-C code. You can achieve this if you use@objc
annotation before the property. (or@objcMembers
on the class)Each style have to subclass NSObject.
It contains stylable property definitions. Important note that you have to use the exactly same name in descriptors, what you use in the UI component. So if you have abackgroundColor
property inUIView
, you have to define by the same name in the descriptor and you have to use@objc
annotation before protocol, like the following:
@objcprotocolViewStyleDescriptor:StyleDescriptor{varbackgroundColor:UIColor{get}}
There is an extension onStyleDescriptor
protocol in the Example project, so you can follow this pattern:
extensionStyleDescriptor{varcolors:ColorPalette{SuitUp.shared.currentTheme?.colorsas!ColorPalette}varfonts:FontPalette{SuitUp.shared.currentTheme?.fontsas!FontPalette}varimages:ImagePalette{SuitUp.shared.currentTheme?.imagesas!ImagePalette}}
or use the very long form whenever needed:
(SuitUp.shared.currentTheme?.colorsas?ColorPalette).primary
You can set style by a style instance given to theapply(style:)
function. It is available through a UIView extension.
primaryView.apply(style:PrimaryViewStyle())
About
Easy to use and lightweight theme manager for iOS applications written in Swift with UIKit, but taking advantages of Objective-C reflection capabilities.