A simpler color picker for SwiftUI on macOS
[中文版本]
This package lets you to add grid-style color picker on macOS (similar to the one on iOS)
macOS 11.0+
Add https://github.com/lihaoyun6/MatrixColorSelector
to your project using Swift Package Manager in Xcode
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)
...