ColorWellKit

1.1.2

A versatile alternative to NSColorWell for Cocoa and ColorPicker for SwiftUI
jordanbaird/ColorWellKit

What's New

ColorWellKit 1.1.2

2023-12-29T20:04:31Z

This release includes minor internal changes.

Full Changelog: 1.1.1...1.1.2

ColorWellKit

Continuous Integration Release Swift Versions Docs License

A versatile alternative to NSColorWell for Cocoa and ColorPicker for SwiftUI.

ColorWellKit is designed to mimic the appearance and behavior of the color well designs introduced in macOS 13 Ventura, ideal for use in apps that are unable to target the latest SDK. While a central goal of ColorWellKit is to maintain a similar look and behave in a similar way to Apple's design, it is not intended to be an exact clone. There are a number of subtle design differences ranging from the way system colors are handled to the size of the drop shadow. In practice, there are very few notable differences:

Install

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/jordanbaird/ColorWellKit", from: "1.1.2")

Usage

Read the full documentation here

SwiftUI

Create a ColorWell and add it to your view hierarchy. There are a wide range of initializers and modifiers to choose from, allowing you to set the color well's color, label, and style.

import SwiftUI
import ColorWellKit

struct ContentView: View {
    @Binding var textColor: Color

    var body: some View {
        VStack {
            ColorWell("Text Color", selection: $textColor)
                .colorWellStyle(.expanded)

            MyCustomTextEditor(textColor: $textColor)
        }
    }
}

Cocoa

Create a CWColorWell using one of the available initializers, or use an IBOutlet to create a connection to a Storyboard or NIB file. Respond to color changes using your preferred design pattern.

import Cocoa
import ColorWellKit

class ViewController: NSViewController {
    @IBOutlet var colorWell: CWColorWell!
    @IBOutlet var textEditor: NSTextView!

    override func viewDidLoad() {
        colorWell.style = .expanded
        if let textColor = textEditor.textColor {
            colorWell.color = textColor
        }
    }

    @IBAction func updateTextColor(sender: CWColorWell) {
        textEditor.textColor = sender.color
    }
}

License

ColorWellKit is available under the MIT license.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Apr 18 2024 07:33:49 GMT-0900 (Hawaii-Aleutian Daylight Time)