A Swift library to display a customizable color picker for macOS.
- Themable, allow your users to change between provided themes.
- Configurable color palettes
- Configurable in Interface Builder or by code.
- Color picker support to allow selecting a color from the screen
- Configurable recent colors support
- Drag and drop support
https://github.com/dagronf/DSFColorPicker to your project
Unfortunately, Xcode has a LOT of problems displaying
@IBDesignable content in Interface Builder if the content comes from a Swift Package. Sometimes it displays, sometimes it doesn't and displays an error about tvOS. I've reported this to Apple in many forms over the years and nothing has been done about it - my guess is the emphasis is moving heavily to SwiftUI previews and this bug is becoming less and less relevant to them.
So what does this mean? You will still be able to create and configure your color picker within Interface Builder, however the pretty previews may or may not display in Interface Builder. Your app will display fine, its just that IB has platform problems when it comes to Swift Package imports.
You can configure your control in interface builder completely. Drop in a custom view, change the custom type to DSFColorView (or an overload) and choose your display theme using the 'Named Theme' setting in the custom types
Configurable using a 2d array of colors, for example
A 5x4 grid
let theme = DSFColorPickerTheme(name: "default", argbValueGrid: [ [0xF5402C, 0xEB1360, 0x9C1BB1, 0x6634B8, 0x3D4DB7], [0x47AE4A, 0x009687, 0x01BBD5, 0x00A6F6, 0x0C93F5], [0x89C43F, 0xCCDD1E, 0xFFEC17, 0xFEC001, 0xFF9800], [0x000000, 0x5E7C8B, 0x9D9D9D, 0x7A5447, 0xFF5506]] ) self.colorView.selectedTheme = theme
A single row with no recents
let theme = DSFColorPickerTheme(name: "Simple Line", argbValueGrid: [ [0xE0BA4240, 0xE0F0C976, 0xE096A873, 0xE089C9B8, 0xE0AFE6E4, 0xE07AA3C0, 0xE08B719F, 0xE0DB849A]] ) self.showRecents = false self.colorView.selectedTheme = theme
The number of recent colors (if shown) is the same as the number of columns in the color grid
- Show or hide the themes in the control
- Show or hide the 'selected' button
- Show or hide recent colors
- Show or hide titles within the control
- Set the cell width and height
- Set the spacing between the color cells
Color sampling support
As of macOS 10.15, your app will require Screen Recording permissions to use the color sampler (the eye dropper).
The first time a user selects the eye-dropper, macOS will display a dialog asking for permission.
You can view the Screen Recording permissions for apps in the system preferences
Security & Privacy pane.
System Preferences > Security & Privacy > Privacy > Screen Recording
Supply a set of themes, and configure the control to display the theme selector.
Drag and drop support
- Drag from the picker to any other component (eg. a color well) that supports dropping colors
- Drag colors into the control
Dark mode support
Automatically adjusts to light and dark modes dynamically
High contrast support
Dynamically adjusts to high-contrast display modes
Accessibility support (preliminary)
- High contrast support
- VoiceOver reads out 'named' color views as they are interacted with (" Color Selector")
Updated the package to depend on the
DSFColorSamplerpackage instead of embedding an older version of the source.
Removed 'direct' method of installing as the SPM package now depends on
- Fixed a compile bug when archiving (Github issue tracker)
MIT. Use it for anything you want, just attribute my work. Let me know if you do use it somewhere, I'd love to hear about it!
MIT License Copyright (c) 2021 Darren Ford Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.