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, usingNSAppearanceNameVibrantDark) - a
SystemTheme(which dynamically resolve to eitherLightThemeor `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
Themeclasses conforming to this protocol andNSObject - provide user themes (
UserTheme) with.themefiles
Please check the provided Demo.app project for sample implementations of both.
-
Unique theme identifier.
Declaration
Swift
var identifier: String -
Theme display name.
Declaration
Swift
var displayName: String -
Theme short display name.
Declaration
Swift
var shortDisplayName: String -
Is this a dark theme?
Declaration
Swift
var isDarkTheme: Bool
-
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
Backgroundin 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?
-
isLightThemeExtension methodIs this a light theme?
This method is not available from Objective-C. Alternative code:
!aTheme.isDarkThemeDeclaration
Swift
public var isLightTheme: Bool -
isSystemThemeExtension methodIs this the system theme? If true, theme automatically resolve to
ThemeManager.lightThemeorThemeManager.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 -
isUserThemeExtension methodIs 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 methodApply 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 methodTheme asset for the specified key. Supported assets are
NSColor,NSGradient,NSImageandNSString.This function is overriden by
UserTheme.This method is not available from Objective-C.
Declaration
Swift
public func themeAsset(_ key: String) -> Any?Parameters
keyA color name, gradient name, image name or a theme string
Return Value
The theme value for the specified key.
-
hasThemeAsset(_:)Extension methodChecks 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) -> BoolParameters
keyA color name, gradient name, image name or a theme string
Return Value
trueif theme provides an asset for the given key;falseotherwise. -
defaultFallbackForegroundColorExtension methodDefault foreground color to be used on fallback situations when no
fallbackForegroundColorwas specified by the theme.This method is not available from Objective-C. Alternative code:
aTheme.isDarkTheme ? NSColor.whiteColor : NSColor.blackColorDeclaration
Swift
var defaultFallbackForegroundColor: NSColor -
defaultFallbackBackgroundColorExtension methodDefault background color to be used on fallback situations when no
fallbackBackgroundColorwas specified by the theme (background color is a color method that containsBackgroundin its name).This method is not available from Objective-C. Alternative code:
aTheme.isDarkTheme ? NSColor.blackColor : NSColor.whiteColorDeclaration
Swift
var defaultFallbackBackgroundColor: NSColor -
defaultFallbackGradientExtension methodDefault gradient to be used on fallback situations when no
fallbackForegroundColorwas 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? -
defaultFallbackImageExtension methodDefault 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 -
effectiveThemeExtension methodEffective 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.lightThemeorThemeManager.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 methodTheme description.
Declaration
Swift
public func themeDescription(_ theme: Theme) -> String
View on GitHub
Install in Dash
Theme Protocol Reference