https://github.com/fredevteam/tkthememanagermodule
theme manager module
https://github.com/fredevteam/tkthememanagermodule
ios macos swift theme
Last synced: about 2 months ago
JSON representation
theme manager module
- Host: GitHub
- URL: https://github.com/fredevteam/tkthememanagermodule
- Owner: FredevTeam
- License: mit
- Created: 2021-07-10T09:19:02.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2021-07-11T08:24:41.000Z (almost 5 years ago)
- Last Synced: 2025-10-10T22:48:10.429Z (9 months ago)
- Topics: ios, macos, swift, theme
- Language: Swift
- Size: 21.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TKThemeManagerModule
[](https://travis-ci.org/playtomandjerry@outlook.com/TKThemeManagerModule)
[](https://cocoapods.org/pods/TKThemeManagerModule)
[](https://cocoapods.org/pods/TKThemeManagerModule)
[](https://cocoapods.org/pods/TKThemeManagerModule)
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
## Installation
TKThemeManagerModule is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'TKThemeManagerModule'
```
## example
### 1. create theme protocl
```
protocol ThemeProtocol:Theme {
var textColor: UIColor { get }
var labelBackgroudColor: UIColor { get }
var backgroudColor: UIColor { get }
}
```
### 2. create theme object exmaple: Dark, Light
* Dark Theme
```
struct DarkTheme : ThemeProtocol{
var textColor: UIColor = UIColor.yellow
var labelBackgroudColor: UIColor = UIColor.green
var backgroudColor: UIColor = UIColor.red
}
```
* Light Theme
```
struct LightTheme: ThemeProtocol {
var textColor: UIColor = UIColor.red
var labelBackgroudColor: UIColor = UIColor.blue
var backgroudColor: UIColor = UIColor.gray
}
```
you can create other theme struct or class
and you can create theme type enum manager theme obj, for example:
```
enum ThemeType {
case light
case dark
}
extension ThemeType {
var theme: ThemeProtocol {
switch self {
case .dark:
return DarkTheme.init()
default:
return LightTheme.init()
}
}
}
```
## 3. init manage and set default theme
```
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
ThemeManager.shared.switch(ThemeType.light.theme)
return true
}
```
## 4. Operation of theme change
### use notification
has two notification , Before the change `themeWillUpdateNotification` and After the change `themeUpdateEndNotification`
```
1. add notificaton observer
NotificationCenter.default.addObserver(self, selector: #selector(themeChangeNotification), name: .themeUpdateEndNotification, object: nil)
@objc private func themeChangeNotification() {
// TODO: update for theme
}
```
### use protocol
```
label.theme.apply(ThemeProtocol.self) { [weak self] view, theme in
// TODO: update for theme ,
// view is label,
// theme is After the change
}
```
## 5. change theme
```
ThemeManager.shared.switch(ThemeType.dark.theme)
```
## Author
FredevTeam@outlook.com, playtomandjerry@gmail.com
## License
TKThemeManagerModule is available under the MIT license. See the LICENSE file for more info.