/MatrixColorSelector

A simpler color picker for SwiftUI on macOS / 适用于 macOS 矩阵式颜色选择器

Primary LanguageSwiftGNU Affero General Public License v3.0AGPL-3.0

MatrixColorSelector

A simpler color picker for SwiftUI on macOS
[中文版本]

Introduction

This package lets you to add grid-style color picker on macOS (similar to the one on iOS)

Requirements

macOS 11.0+

Install

Add https://github.com/lihaoyun6/MatrixColorSelector to your project using Swift Package Manager in Xcode

Usage

First, import MatrixColorSelector into your code:

import MatrixColorSelector

Then you can:

import SwiftUI
import MatrixColorSelector

struct ContentView: View {
    @State var color: Color = .black
    
    var body: some View {
        MatrixColorSelector("Select Color:", selection: $color)
    }
}

This will generate a MatrixColorSelector button, and when you click it, it will bring up the popover. Or you can use MatrixColorSelectorView() as the content view and wrap it yourself, this will allow you to customize the style of the button.

If you don't want the color picker to include the "Show Colors..." button (clicking it will open the macOS built-in color picker panel), you can do this:

...
MatrixColorSelector("some-text", selection: $color, noMoreColors: false)
...