ColorWellKit It's a SwiftPackage for NSColorWell for Cocoa and ColorPicker.
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 |
---|---|
CWColorWell
ColorWell
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)
}
}
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)
}
}
}
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.
DevLiuSir Software Engineer |
---|
ColorWellKit
is available under the MIT license. See the LICENSE file for more info.