An iOS theme framework that supports Objective-C, Swift, and SwiftUI simultaneously.
🇨🇳 Looking for the Chinese README? See README_CN.md.
- Centralized theme manager with system-following or manual light/dark selection.
- Dynamic UIKit colors via
UIColorhelpers andThemeDynamicColor. - SwiftUI bridge with
Colorhelpers andThemeObserver. - Customizable palettes and tokens with fallback support.
- Demo app showcasing UIKit + SwiftUI usage.
- iOS 13+
- Swift tools 5.9 (Xcode 16+)
- File > Add Package Dependencies...
- Enter the URL:
https://github.com/FollowmeTech/ThemeKit.git - Add
ThemeKitto your target.
.package(url: "https://github.com/FollowmeTech/ThemeKit.git", from: "1.0.0")Then add the product:
.product(name: "ThemeKit", package: "ThemeKit")Configure the theme manager at app launch (SceneDelegate or AppDelegate):
import ThemeKit
ThemeManager.shared.updateSystemInterfaceStyleIfNeeded(windowScene.traitCollection)
ThemeManager.shared.configure(with: ThemeCatalog.default)
ThemeManager.shared.register(window: window)Use theme colors:
view.backgroundColor = .themeBackground
label.textColor = .themePrimaryText
button.tintColor = .themeAccentSwitch themes:
ThemeManager.shared.selectTheme(.dark) // .light / .followSystemUse ThemeObserver to trigger view updates when the selection changes:
import ThemeKit
@StateObject private var themeObserver = ThemeObserver()
var body: some View {
VStack(spacing: 12) {
Text("ThemeKit")
.foregroundColor(.themePrimaryText)
Text(themeObserver.selection == .dark ? "Dark" : "Light")
.foregroundColor(.themeSecondaryText)
}
.padding()
.background(Color.themeBackground)
}@import ThemeKit;
[[ThemeManager shared] selectTheme:ThemeSelectionDark];
self.view.backgroundColor = [UIColor themeBackground];
self.label.textColor = [UIColor themePrimaryText];Extend ThemeColorToken, override palettes, and reconfigure the manager:
extension ThemeColorToken {
static let demoCard = ThemeColorToken("demo.card")
}
let base = ThemeCatalog.default
let lightPalette = base.lightTheme.palette.applyingOverrides([
.demoCard: UIColor(red: 0.85, green: 0.96, blue: 0.90, alpha: 1.0),
.accent: .systemPink
])
let darkPalette = base.darkTheme.palette.applyingOverrides([
.demoCard: UIColor(red: 0.26, green: 0.08, blue: 0.14, alpha: 1.0),
.accent: .systemOrange
])
let catalog = ThemeCatalog(
lightTheme: Theme(interfaceStyle: .light, palette: lightPalette),
darkTheme: Theme(interfaceStyle: .dark, palette: darkPalette)
)
ThemeManager.shared.configure(with: catalog)Open the sample app and run the ThemeDemo scheme:
open Demo/ThemeDemo.xcodeprojswift testMIT. See LICENSE.