Readme updates

This commit is contained in:
Jonathan Cardasis 2020-03-14 17:56:42 -04:00
parent 1617660555
commit 90a988bfcc
2 changed files with 40 additions and 31 deletions

BIN
.github/ChromaColorPicker.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 MiB

View File

@ -6,21 +6,22 @@
<img src="https://img.shields.io/badge/Swift-5.0-orange.svg" />
<img src="https://img.shields.io/badge/platform-iOS-lightgray.svg" />
<img src="https://img.shields.io/badge/license-MIT-blue.svg" />
<img src="https://img.shields.io/badge/Carthage-compatible-green.svg" />
<img src="https://travis-ci.com/joncardasis/ChromaColorPicker.svg?branch=develop" />
<img src="https://img.shields.io/badge/Cocoapods-✔-green.svg" />
<img src="https://img.shields.io/badge/Carthage-✔-green.svg" />
<img src="https://travis-ci.com/joncardasis/ChromaColorPicker.svg?branch=master" />
</p>
An intuitive HSB color picker built in Swift. Supports multiple selection handles and is customizable to your needs.
> TODO: Image / GIF
<p align="center">
<img src=".github/ChromaColorPicker.gif" width="365" alt="ChromaColorPicker GIF" />
</p>
## Examples
```Swift
let colorPicker = ChromaColorPicker(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
addSubview(colorPicker)
// Optional: Add multiple handles to the color picker
// Optional: Attach a ChromaBrightnessSlider to a ChromaColorPicker
let brightnessSlider = ChromaBrightnessSlider(frame: CGRect(x: 0, y: 0, width: 280, height: 32))
addSubview(brightnessSlider)
@ -28,20 +29,35 @@ addSubview(brightnessSlider)
colorPicker.connect(brightnessSlider) // or `brightnessSlider.connect(to: colorPicker)`
```
- View the _Example_ app for more.
## Usage
### Multiple Handles
```Swift
// Add handles
{TODO}
// Add handle at color
let peachColor = UIColor(red: 1, green: 203 / 255, blue: 164 / 255, alpha: 1)
colorPicker.addHandle(at: peachColor)
// Add a custom handle
{TODO}
// Add handle with reference
let customHandle = ChromaColorHandle()
customHandle.color = UIColor.purple
colorPicker.addHandle(customHandle)
// Remove handles
{TODO}
// Add handle and keep reference
let handle = colorPicker.addHandle(at: .blue)
```
### Supported UIControlEvents
### Custom Handle Icon
```Swift
let homeHandle = ChomaColorHandle(color: .blue)
let imageView = UIImageView(image: #imageLiteral(resourceName: "home-icon").withRenderingMode(.alwaysTemplate))
imageView.contentMode = .scaleAspectFit
imageView.tintColor = .white
homeHandle.accessoryView = imageView
homeHandle.accessoryViewEdgeInsets = UIEdgeInsets(top: 2, left: 4, bottom: 4, right: 4)
colorPicker.addHandle(homeHandle)
```
## Installation
### Carthage
@ -57,30 +73,18 @@ pod 'ChromaColorPicker'
Add all files from the `Source` folder to your project.
## Components
### ChromaColorPicker
An HSB color picker with support for adding multiple color selection handles.
| Component | Description |
| :-------: | :---------: |
| ChromaColorPicker | An HSB color picker with support for adding multiple color selection handles. |
| ChromaBrightnessSlider | A slider UIControl which can be attached to any `ChromaColorPicker` via the `connect(to:)` method. ChromaBrightnessSlider can also function as a stand-alone UIControl. |
### ChromaBrightnessSlider
[ChromaBrightnessSlider]() is a slider UIControl which can be attached to any `ChromaColorPicker` via the `connect(to:)` method. ChromaBrightnessSlider can also function as a stand-alone UIControl.
### Supported UIControlEvents
You can observe on the following UIControlEvents via `UIControl`'s `addTarget` method:
```Swift
addTarget(self, action: #selector(sliderDidValueChange(_:)), for: .valueChanged)
@objc func sliderDidValueChange(_ slider: ChromaBrightnessSlider) {
print("new color: \(slider.currentColor)")
}
```
## Supported UIControlEvents
Both `ChromaBrightnessSlider` and `ChromaColorPicker` conform to UIControl. Each send UIControlEvents which can be observed via via `UIControl`'s `addTarget` method.
_ChromaColorPicker_
| Event | Description |
| :-----------------:|:-------------|
| `.touchDown`(no) | Called when a handle is first grabbed. |
| `.touchUpInside`(no) | Called when a handle is let go. |
| `.valueChanged` | Called whenever the color has changed. |
| `.touchDragInside`(no) | Called when a handle has moved via a drag action. |
| `.touchUpInside` | Called when a handle is released. |
_ChromaBrightnessSlider_
@ -90,8 +94,13 @@ _ChromaBrightnessSlider_
| `.valueChanged` | Called whenever the slider is moved and the value has changed. |
| `.touchUpInside` | Called when the slider handle is released. |
##### Example
```Swift
// Example
brightnessSlider.addTarget(self, action: #selector(sliderDidValueChange(_:)), for: .valueChanged)
@objc func sliderDidValueChange(_ slider: ChromaBrightnessSlider) {
print("new color: \(slider.currentColor)")
}
```
## License