Pragmatic color utilities for SwiftUI and UIKit.
ColorKit helps you parse hex colors, check accessibility contrast, generate palettes, build gradients, and simulate color‑vision deficiencies — all with a tiny, focused API that feels at home in Swift.
Add the package to Xcode or your Package.swift using the public repo and a tag.
- URL:
https://github.com/ckdash-git/ColorKit.git - Minimum platforms: iOS 13+, macOS 12+, tvOS 13+, watchOS 6+
// Package.swift
.dependencies: [
.package(url: "https://github.com/ckdash-git/ColorKit.git", from: "0.1.1")
]
.targets: [
.target(
name: "App",
dependencies: [
.product(name: "ColorKit", package: "ColorKit")
]
)
]In Xcode: File → Add Packages… → paste the URL → add the ColorKit product.
Add to your Podfile (iOS example):
platform :ios, '13.0'
use_frameworks!
target 'App' do
pod 'ColorsKit', '~> 0.1'
endThen run pod install and import the module:
import ColorKitNote: The CocoaPods pod name is ColorsKit, but the Swift module is ColorKit.
- Hex parsing to and from
RGBA(#RGB,#RGBA,#RRGGBB,#RRGGBBAA) - WCAG contrast ratio and AA/AAA compliance checks
- Palette generation around a base color
- SwiftUI/UIColor helpers (dynamic light/dark, gradients)
- Color‑blindness simulation (protanopia, deuteranopia, tritanopia)
Add the package to Xcode or your Package.swift using the public repo and a tag.
- URL:
https://github.com/ckdash-git/ColorKit.git - Minimum platforms: iOS 13+, macOS 12+, tvOS 13+, watchOS 6+
// Package.swift
.dependencies: [
.package(url: "https://github.com/ckdash-git/ColorKit.git", from: "0.1.1")
]
.targets: [
.target(
name: "App",
dependencies: [
.product(name: "ColorKit", package: "ColorKit")
]
)
]In Xcode: File → Add Packages… → paste the URL → add the ColorKit product.
Add to your Podfile (iOS example):
platform :ios, '13.0'
use_frameworks!
target 'App' do
pod 'ColorsKit', '~> 0.1'
endThen run pod install and import the module:
import ColorKitNote: The CocoaPods pod name is ColorsKit, but the Swift module is ColorKit.
import ColorKit
// Hex → RGBA
let fg = try HexColorFormatter.parse("#1A73E8")
let bg = try HexColorFormatter.parse("#FFFFFF")
// Contrast ratio + WCAG
let ratio = ColorMath.contrastRatio(fg, bg)
let isAA = Accessibility.meets(.AA, foreground: fg, background: bg)
let isAAA = Accessibility.meets(.AAA, foreground: fg, background: bg)
// Palette around a base color
let palette = PaletteGenerator.generate(from: "#1A73E8", steps: 6, range: 0.25)
// Simulate color‑vision deficiency
let protanopia = ColorBlindnessSimulator.simulate(.protanopia, rgba: fg)import SwiftUI
import ColorKit
// Create Color from hex
let primary = Color(hex: "#0A84FF")
// Dynamic light/dark Color (bridges via UIKit on iOS)
let dynamic = Color.dynamic(lightHex: "#FFFFFF", darkHex: "#000000")
// LinearGradient from hex list
let gradient = SwiftUIGradientBuilder.linear(hexColors: ["#0A84FF", "#5E5CE6"]) import UIKit
import ColorKit
let primary = UIColor(hex: "#0A84FF")
let dynamic = UIColor.dynamic(lightHex: "#FFFFFF", darkHex: "#000000")A tiny command‑line demo lives in Example/ConsumerSample/.
- Run:
cd Example/ConsumerSample && swift run - Shows: hex parsing, contrast ratio, palette generation, and color‑blindness simulation.
ColorCore:RGBA,HexColorFormatter,ColorMath,Accessibility,Theme,ThemeManagerColorUtilities:PaletteGenerator,AccessibilityUtils,ColorBlindnessSimulatorColorExtensions: SwiftUI/UIColor helpers, gradientsColorPalettes: Predefined themes and palette helpers
Color.dynamicbridges toColor(uiColor:)on iOS/tvOS.- On iOS/tvOS < 15,
Color.dynamicfalls back to the light variant. - CocoaPods support: iOS and macOS in
0.1.0; tvOS/watchOS coming in a follow‑up release.
This repo follows semantic versioning. Start with 0.1.0 and evolve via tags.
MIT. See LICENSE.
Issues and PRs are welcome. If you have an idea or find a bug, open an issue with a short repro or proposal. Thank you!