Skip to content

Latest commit

 

History

History
142 lines (89 loc) · 5.07 KB

README.md

File metadata and controls

142 lines (89 loc) · 5.07 KB

ColorWellKit It's a SwiftPackage for NSColorWell for Cocoa and ColorPicker.

Overview

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.

Light mode Dark mode
light-popover dark-popover

Topics

Color Wells in Cocoa

  • CWColorWell

Color Wells in SwiftUI

  • ColorWell

Cocoa

Create a CWColorWell using one of the available initializers. Respond to color changes using your preferred design pattern (see doc:ColorObservation):

import Cocoa
import ColorWellKit

class ContentViewController: NSViewController {
    @IBOutlet var textControls: NSStackView!
    @IBOutlet var textEditor: MyCustomNSTextEditor!

    private var colorObservation: NSKeyValueObservation?

    override func viewDidLoad() {
        let colorWell = CWColorWell(style: .expanded)
        colorWell.color = textEditor.fontColor

        colorObservation = colorWell.observe(\.color) { colorWell, _ in
            textEditor.fontColor = colorWell.color
        }

        textControls.addArrangedSubview(colorWell)
    }
}

SwiftUI

Create a ColorWell and add it to your view hierarchy. There are a wide range of initializers, as well as several 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 fontColor: Color

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

            MyCustomTextEditor(fontColor: fontColor)
        }
    }
}

Install

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate ColorWellKit into your Xcode project using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...:

https://github.com/DevLiuSir/ColorWellKit.git, :branch="master"

Official Tutorial “Swift Package Manager” tab in Xcode.

Author

DevLiuSir

Software Engineer

License

ColorWellKit is available under the MIT license. See the LICENSE file for more info.