Latest 1.0.1
Homepage https://github.com/daltyboy11/DSColorPicker
License MIT
Platforms ios 9.0
Authors

Lightweight views for your color picking needs.

CocoaPods Install

Add pod 'DSColorPicker' to your Podfile and then run $ pod install.

Usage

To use the provided classes, import DSColorPicker.

Presenting the color picker

After creating either a Grid or Circle DSColorPickerView, invoke show(animated:completion:). By default, the presentation is animated and the completion handler does nothing.

Example:

In a view controller

let gridColorPickerView = DSGridColorPickerView(frame: self.view.bounds, delegate: self, dataSource: self)
view.addSubview(gridColorPickerView)
gridColorPickerView.show()

Presenting

Handling user interaction

Receive a notification when the user selects a color in the picker by adopting the DSColorPickerViewDelegate protocol.

Example:

extension ViewController: DSColorPickerViewDelegate {
    // A UIViewController subclass is the delegate for a picker view, and changes its view's background color when a color is selected by the user in a picker view.
    func didSelect(color: UIColor, pickerView: DSColorPickerViewType) {
        view.backgroundColor = color
    }

}

User interaction

Reloading a color picker

After updating a color picker’s dataSource in some manner, invoke reload(animated:completion:) to communicate the changes to the color picker.

Examples:

Circle
Grid

Providing data to the picker

Adopt the DSColorPickerViewDataSource to provide the number of colors and color values to the picker.

Example of a conforming view controller that provides various RGB formatted colors to the picker:

extension ViewController: DSColorPickerViewDataSource {
    var numberOfColors: Int {
        return 16
    }

    func color(at index: Int) -> CGColor {
        let color = UIColor(hue: CGFloat(index) / CGFloat(self.numberOfColors), saturation: 1.0, brightness: 1.0, alpha: 1.0).cgColor
        return color
    }
}

Providing data to a DSGridColorPickerView

To provide data to a DSGridColorPickerView, adopt the DSGridColorPickerViewDataSource protocol. This data source has the same requirements as the DSColorPickerViewDataSource, with the addition of maxColumns, which specifies the maximum allowable number of columns in the grid.

Example – Adding colors one by one to the picker with maxColumns set to 4:

Latest podspec

{
    "name": "DSColorPicker",
    "version": "1.0.1",
    "summary": "DSColorPicker is a lightweight view that acts as a color picking utility. There are two available styles: grid and circle.",
    "homepage": "https://github.com/daltyboy11/DSColorPicker",
    "license": "MIT",
    "authors": {
        "Dalton Sweeney": "[email protected]"
    },
    "social_media_url": "http://twitter.com/daltyboy11",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/daltyboy11/DSColorPicker.git",
        "tag": "1.0.1"
    },
    "source_files": [
        "DSColorPicker/*.swift",
        "DSColorPicker/Protocols/*.swift",
        "DSColorPicker/Pickers/*.swift"
    ],
    "swift_version": "4.2"
}

Pin It on Pinterest

Share This