Theme

public protocol Theme: NSObjectProtocol

Theme protocol: the base of all themes.

ThemeKit makes available, without any further coding:

  • a LightTheme (the default macOS theme)
  • a DarkTheme (the dark macOS theme, using NSAppearanceNameVibrantDark)
  • a SystemTheme (which dynamically resolve to either LightTheme or `DarkTheme depending on the macOS preference at System Preferences > General > Appearance)

You can choose wheter or not to use these, and you can also implement your custom themes by:

  • implementing native Theme classes conforming to this protocol and NSObject
  • provide user themes (UserTheme) with .theme files

Please check the provided Demo.app project for sample implementations of both.

  • Optional: foreground color to be used on when a foreground color is not provided by the theme.

    Declaration

    Swift

    @objc optional var fallbackForegroundColor: NSColor?
  • Optional: background color to be used on when a background color (a color which contains Background in its name) is not provided by the theme.

    Declaration

    Swift

    @objc optional var fallbackBackgroundColor: NSColor?
  • Optional: gradient to be used on when a gradient is not provided by the theme.

    Declaration

    Swift

    @objc optional var fallbackGradient: NSGradient?
  • Optional: image to be used on when an image is not provided by the theme.

    Declaration

    Swift

    @objc optional var fallbackImage: NSImage?
  • isLightTheme Extension method

    Is this a light theme?

    This method is not available from Objective-C. Alternative code:

    !aTheme.isDarkTheme
    

    Declaration

    Swift

    public var isLightTheme: Bool
  • isSystemTheme Extension method

    Is this the system theme? If true, theme automatically resolve to ThemeManager.lightTheme or ThemeManager.darkTheme, accordingly to System Preferences > General > Appearance.

    This method is not available from Objective-C. Alternative code:

    [aTheme.identifier isEqualToString:TKSystemTheme.identifier]
    

    Declaration

    Swift

    public var isSystemTheme: Bool
  • isUserTheme Extension method

    Is this a user theme?

    This method is not available from Objective-C. Alternative code:

    [aTheme isKindOfClass:[TKUserTheme class]]
    

    Declaration

    Swift

    public var isUserTheme: Bool
  • apply() Extension method

    Apply theme (make it the current one).

    This method is not available from Objective-C. Alternative code:

    [[TKThemeManager sharedManager] setTheme:aTheme]
    

    Declaration

    Swift

    public func apply()
  • themeAsset(_:) Extension method

    Theme asset for the specified key. Supported assets are NSColor, NSGradient, NSImage and NSString.

    This function is overriden by UserTheme.

    This method is not available from Objective-C.

    Declaration

    Swift

    public func themeAsset(_ key: String) -> Any?

    Parameters

    key

    A color name, gradient name, image name or a theme string

    Return Value

    The theme value for the specified key.

  • hasThemeAsset(_:) Extension method

    Checks if a theme asset is provided for the given key.

    This function is overriden by UserTheme.

    This method is not available from Objective-C.

    Declaration

    Swift

    public func hasThemeAsset(_ key: String) -> Bool

    Parameters

    key

    A color name, gradient name, image name or a theme string

    Return Value

    true if theme provides an asset for the given key; false otherwise.

  • Default foreground color to be used on fallback situations when no fallbackForegroundColor was specified by the theme.

    This method is not available from Objective-C. Alternative code:

    aTheme.isDarkTheme ? NSColor.whiteColor : NSColor.blackColor
    

    Declaration

    Swift

    var defaultFallbackForegroundColor: NSColor
  • Default background color to be used on fallback situations when no fallbackBackgroundColor was specified by the theme (background color is a color method that contains Background in its name).

    This method is not available from Objective-C. Alternative code:

    aTheme.isDarkTheme ? NSColor.blackColor : NSColor.whiteColor
    

    Declaration

    Swift

    var defaultFallbackBackgroundColor: NSColor
  • defaultFallbackGradient Extension method

    Default gradient to be used on fallback situations when no fallbackForegroundColor was specified by the theme.

    This method is not available from Objective-C. Alternative code:

    [[NSGradient alloc] initWithStartingColor:(aTheme.isDarkTheme ? NSColor.blackColor : NSColor.whiteColor) endingColor:(aTheme.isDarkTheme ? NSColor.whiteColor : NSColor.blackColor)]
    

    Declaration

    Swift

    var defaultFallbackGradient: NSGradient?
  • defaultFallbackImage Extension method

    Default image to be used on fallback situations when no image was specified by the theme.

    This method is not available from Objective-C. Alternative code:

    [[NSImage alloc] initWithSize:NSZeroSize]
    

    Declaration

    Swift

    var defaultFallbackImage: NSImage
  • effectiveTheme Extension method

    Effective theme, which can be different from itself if it represents the system theme, respecting System Preferences > General > Appearance (in that case it will be either ThemeManager.lightTheme or ThemeManager.darkTheme).

    This method is not available from Objective-C. Alternative code:

    [aTheme.identifier isEqualToString:TKSystemTheme.identifier] ? (aTheme.isDarkTheme ? TKThemeManager.darkTheme : TKThemeManager.lightTheme) : aTheme;
    

    Declaration

    Swift

    var effectiveTheme: Theme
  • themeDescription(_:) Extension method

    Theme description.

    Declaration

    Swift

    public func themeDescription(_ theme: Theme) -> String