https://github.com/0xwdg/colors
Colors is a Swift Package to enable all system colors in SwiftUI trough a Color extension. Colors which were previously only available in UIColor/NSColor are now available in Color as well.
https://github.com/0xwdg/colors
0xwdg appkit color hacktoberfest nscolor package spm swift swiftlang swiftui uicolor uikit xcode
Last synced: 8 months ago
JSON representation
Colors is a Swift Package to enable all system colors in SwiftUI trough a Color extension. Colors which were previously only available in UIColor/NSColor are now available in Color as well.
- Host: GitHub
- URL: https://github.com/0xwdg/colors
- Owner: 0xWDG
- License: mit
- Created: 2024-08-22T20:08:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-20T20:15:18.000Z (about 1 year ago)
- Last Synced: 2025-07-04T13:29:53.483Z (9 months ago)
- Topics: 0xwdg, appkit, color, hacktoberfest, nscolor, package, spm, swift, swiftlang, swiftui, uicolor, uikit, xcode
- Language: Swift
- Homepage: https://0xwdg.github.io/Colors/
- Size: 432 KB
- Stars: 33
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Colors
Colors is a Swift Package to enable all system colors in SwiftUI trough a `Color` extension.
Colors which were previously only available in `UIColor`/`NSColor` are now available in `Color` as well.
[](https://swiftpackageindex.com/0xWDG/Colors)
[](https://swiftpackageindex.com/0xWDG/Colors)
[](https://swift.org/package-manager)

Available colors are: `lightText`, `darkText`, `placeholderText`, `label`, `secondaryLabel`, `tertiaryLabel`, `quaternaryLabel`, `systemBackground`, `secondarySystemBackground`, `tertiarySystemBackground`, `systemFill`, `secondarySystemFill`, `tertiarySystemFill`, `quaternarySystemFill`, `systemGroupedBackground`, `secondarySystemGroupedBackground`, `tertiarySystemGroupedBackground`, `systemGray`, `systemGray2`, `systemGray3`, `systemGray4`, `systemGray5`, `systemGray6`, `separator`, `opaqueSeparator`, `link`, `systemBlue`, `systemCyan`, `systemMint`, `systemPurple`, `systemGreen`, `systemYellow`, `systemOrange`, `systemPink`, `systemRed`, `systemTeal`, `systemIndigo`, `scrubberTexturedBackground`, `textBackgroundColor`, `controlTextColor`, `quaternaryLabelColor`, `findHighlightColor`, `highlightColor`, `shadowColor`, `windowFrameTextColor`, `windowBackgroundColor`, `keyboardFocusIndicatorColor`, `separatorColor`, `selectedControlColor`, `controlBackgroundColor`, `secondaryLabelColor`, `tertiaryLabelColor`, `gridColor`, `alternateSelectedControlTextColor`, `unemphasizedSelectedContentBackgroundColor`, `textColor`, `systemBrown`, `selectedContentBackgroundColor`, `selectedTextColor`, `labelColor`, `placeholderTextColor`, `unemphasizedSelectedTextBackgroundColor`, `disabledControlTextColor`, `headerTextColor`, `linkColor`, `selectedTextBackgroundColor`, `unemphasizedSelectedTextColor`, `controlColor`, `selectedControlTextColor`, `underPageBackgroundColor`, `selectedMenuItemTextColor`.
## Requirements
- Swift 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+
## Installation (Pakage.swift)
```swift
dependencies: [
.package(url: "https://github.com/0xWDG/Colors.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "Colors", package: "Colors"),
]),
]
```
## Installation (Xcode)
1. In Xcode, open your project and navigate to **File** โ **Swift Packages** โ **Add Package Dependency...**
2. Paste the repository URL (`https://github.com/0xWDG/Colors`) and click **Next**.
3. Click **Finish**.
## Usage
```swift
import SwiftUI
import Colors
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, World!")
.foregroundColor(Color.disabledControlTextColor)
}
.padding()
}
}
```
## Extract color from UIColor/NSColor
Use this to add new/missing colors to the `BaseColor` and `Color` extension.
Extract from **UIKit**:
```swift
UIColor.systemPink.createInitializerFor(color: "systemPink")
```
Extract from **AppKit**:
```swift
NSColor.systemPink.createInitializerFor(color: "systemPink")
```
Output:
```swift
/// A color that represents the system-provided systemPink color.
public static let systemPink = Color.dynamicColor(
light: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00),
dark: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00)
)
```
## How to add a new color
1. Add the color to the `BaseColor` struct.
```swift
/// A color that represents the system-provided systemPink color.
public static let systemPink = Color.dynamicColor(
light: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00),
dark: .init(red: 1.00, green: 0.18, blue: 0.33, alpha: 1.00)
)
```
2. Add the color to the `Color` extension.
- Use the native `Color`,`NSColor`,`UIColor.colorName` where possible.
- Add #if os(iOS) / #if os(macOS) where needed.
- Example (works on almost all versions):
```swift
/// A color that represents the system-provided pink color.
public static var systemPink: Color {
#if os(iOS) || os(tvOS)
Color(UIColor.systemPink)
#elseif os(macOS)
Color(NSColor.systemPink)
#else
BaseColor.systemPink
#endif
}
```
- Example 2 (works from a specific iOS/macOS version):
```swift
/// A color that represents the system-provided cyan color.
public static var systemCyan: Color {
#if os(iOS) || os(tvOS)
if #available(iOS 15.0, *) {
Color(UIColor.systemCyan)
} else {
BaseColor.systemCyan
}
#elseif os(macOS)
if #available(macOS 12.0, *) {
Color(NSColor.systemCyan)
} else {
BaseColor.systemCyan
}
#else
BaseColor.systemCyan
#endif
}
```
## Contact
๐ฆ [@0xWDG](https://bsky.app/profile/0xWDG.bsky.social)
๐ [mastodon.social/@0xWDG](https://mastodon.social/@0xWDG)
๐ฆ [@0xWDG](https://x.com/0xWDG)
๐งต [@0xWDG](https://www.threads.net/@0xWDG)
๐ [wesleydegroot.nl](https://wesleydegroot.nl)
๐ค [Discord](https://discordapp.com/users/918438083861573692)
Interested learning more about Swift? [Check out my blog](https://wesleydegroot.nl/blog/).