Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Easy to use and lightweight theme manager for iOS applications written in Swift with UIKit, but taking advantages of Objective-C reflection capabilities.

License

NotificationsYou must be signed in to change notification settings

wupdigital/SuitUp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swift-versionlicense

Introduction

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.

example

Example

Just openSuitUp workspace and have fun!

Installation

UseCocoaPods:

pod'SuitUp'

or you can install manually:

Download it, then drag and drop the contents ofSuitUp/SuitUp folder into your project.

Import

Of course don't miss to importSuitUp where you want to use.

import SuitUp

Themes

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.

Colors, fonts and images

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}}

Registration

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.

Theme change

You can change currently used theme in runtime withchangeTheme(to:) function inSuitUp.

Style

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.

Style descriptor

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}}

How to use items from themes

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

Usage

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp