ThemeManager

public class ThemeManager: NSObject

Use ThemeManager shared instance to perform app-wide theming related operations, such as:

  • Get information about current theme/appearance
  • Change current theme (can also be changed from NSUserDefaults)
  • List available themes
  • Define ThemeKit behaviour
  • ThemeManager shared manager.

    Declaration

    Swift

    public static let shared = ThemeManager()
  • Location of user provided themes (.theme files).

    Ideally, this should be on a shared location, like Application Support/{app_bundle_id}/Themes for example. Here’s an example of how to get this folder (*):

    public var applicationSupportUserThemesFolderURL: URL {
      let applicationSupportURLs = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)
      let thisAppSupportURL = URL(fileURLWithPath: applicationSupportURLs.first!).appendingPathComponent(Bundle.main.bundleIdentifier!)
      return thisAppSupportURL.appendingPathComponent("Themes")
    }
    

    *: force wrapping (!) is for illustrative purposes only.

    You can also bundle these files with your application bundle, if you don’t want them to be changed.

    Declaration

    Swift

    @objc public var userThemesFolderURL: URL?
  • Window theme policies that define which windows should be automatically themed, if any.

    Swift

    By default, all application windows (except NSPanel) will be themed (.themeAllWindows).

    • themeAllWindows: Theme all application windows, except NSPanel subclasses (default).
    • themeSomeWindows: Only theme windows of the specified classes.
    • doNotThemeSomeWindows: Do not theme windows of the specified classes.
    • doNotThemeWindows: Do not theme any window.E.g.:

    E.g.:

    ThemeManager.shared.windowThemePolicy = .themeSomeWindows(windowClasses: [CustomWindow.self])
    

    Objective-C

    By default, all application windows (except NSPanel) will be themed (TKThemeManagerWindowThemePolicyThemeAllWindows).

    • TKThemeManagerWindowThemePolicyThemeAllWindows: Theme all application windows, except NSPanel subclasses (default).
    • TKThemeManagerWindowThemePolicyThemeSomeWindows: Only theme windows of the specified classes (use themableWindowClasses property).
    • TKThemeManagerWindowThemePolicyDoNotThemeSomeWindows: Do not theme windows of the specified classes (use notThemableWindowClasses property).
    • TKThemeManagerWindowThemePolicyDoNotThemeWindows: Do not theme any window.

    Example:

    [TKThemeManager sharedManager].windowThemePolicy = TKThemeManagerWindowThemePolicyThemeSomeWindows;
    [TKThemeManager sharedManager].themableWindowClasses = @[[CustomWindow class]];
    

    NSWindow Extension

    See more

    Declaration

    Swift

    public enum WindowThemePolicy
  • Current window theme policy.

    Declaration

    Swift

    public var windowThemePolicy: WindowThemePolicy = .themeAllWindows
  • ThemeKit notification sent when current theme is about to change.

    Declaration

    Swift

    @objc public static let willChangeThemeNotification = Notification.Name.willChangeTheme
  • ThemeKit notification sent when current theme did change.

    Declaration

    Swift

    @objc public static let didChangeThemeNotification = Notification.Name.didChangeTheme
  • ThemeKit notification sent when system theme did change (System Preference > General > Appearance).

    Declaration

    Swift

    @objc public static let didChangeSystemThemeNotification = Notification.Name.didChangeSystemTheme