Skip to content

Commit 90af467

Browse files
committed
README
1 parent 615d7c3 commit 90af467

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

Assets/ColorSet.png

500 KB
Loading

README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,60 @@ ColorSet
1111
About
1212
-----
1313

14-
...
14+
**`ColorSet` is a macOS utility and framework allowing developers to manage custom interface colors with ease.**
15+
16+
### Rationale
17+
18+
As of macOS 10.14 Mojave, Apple introduced a system-wide dark-mode.
19+
Applications linked with the macOS 10.14 SDK now needs to react to the system appearance changes.
20+
21+
While built-in AppKit UI elements handle this perfectly, an application often relies on custom controls, custom drawing code, or at last custom colors.
22+
23+
As an example, the following code will perfectly react to the dark mode.
24+
This is a system color, so everything is handled automatically by AppKit:
25+
26+
let color = NSColor.textColor
27+
28+
While the following won't change, as the color components are hard-coded:
29+
30+
let color = NSColor( deviceRed: 1, green: 0, blue: 0, alpha: 1 )
31+
32+
Apple provides a nice solution, relying on Asset Catalog files.
33+
As of Xcode 10, you can create custom colors in Asset Catalogs, identified by a name, and optionally containing variants for a specific UI theme or device.
34+
35+
**Unfortunately, this feature is only available for applications running on macOS 10.13 and later.**
36+
It basically means you'll have to drop support for macOS 10.12 and below.
37+
38+
If you need to support macOS 10.12 or below, **Apple's official recommendation (as seen during WWDC18) is to actually hard-code colors using conditional platform-detection code**.
39+
40+
**So here comes `ColorSet`.**
41+
42+
### ColorSet & ColorSetKit
43+
44+
`ColorSet` comes as a macOS application and as a macOS framework.
45+
46+
The application lets you create files containing colors and variants, just as an Asset Catalog File, while the framework allows you, in your application, to retrieve colors from the `.colorset` file using names, just as the macOS 10.13 SDK.
47+
48+
### Creating a `.colorset` file
49+
50+
The application lets you create as many colors as you want, each with a unique name.
51+
For each color, an optional dark variant can be set:
52+
53+
![ColorSet](Assets/ColorSet.png "ColorSet")
54+
55+
### Using ColorSetKit
56+
57+
By default, `ColorSetKit` will look for a file named `Colors.colorset` in your application's bundle.
58+
59+
Colors can be retrieved using a custom method on `NSColor`:
60+
61+
let color = NSColor.colorFromColorSet( "MyCustomColor" )
62+
63+
By themselves, colors won't react to UI theme changes.
64+
But the `colorFromColorSet` method will return the correct color, based on the current UI theme.
65+
66+
This means that if you use custom drawing code, you shouldn't cache color objects, but instead call `colorFromColorSet` directly from your drawing code.
67+
This way, the correct color will be used each time your view is redrawn (which happens automatically when the UI theme changes).
1568

1669
License
1770
-------

0 commit comments

Comments
 (0)