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 eitherLightTheme
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 andNSObject
- provide user themes (
UserTheme
) with.theme
files
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
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 methodIs this a light theme?
This method is not available from Objective-C. Alternative code:
!aTheme.isDarkTheme
Declaration
Swift
public var isLightTheme: Bool
-
isSystemTheme
Extension methodIs this the system theme? If true, theme automatically resolve to
ThemeManager.lightTheme
orThemeManager.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 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
,NSImage
andNSString
.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 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) -> 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. -
defaultFallbackForegroundColor
Extension methodDefault 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
-
defaultFallbackBackgroundColor
Extension methodDefault background color to be used on fallback situations when no
fallbackBackgroundColor
was specified by the theme (background color is a color method that containsBackground
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 methodDefault 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 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
-
effectiveTheme
Extension 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.lightTheme
orThemeManager.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