Coder Social home page Coder Social logo

colorslider's Introduction

ColorSlider

ColorSlider is a Swift color picker with a live preview.

Inspired by Snapchat, ColorSlider lets you drag vertically to pick a range of colors and drag to the edges of the superview to select black and white. You can configure and customize ColorSlider via a simple API, and receive callbacks via UIControlEvents.

ColorSlider

Pod Version Build Status

Version Compatibility

Current Swift compatibility breakdown:

Swift Version Framework Version
3.0 master
2.3 2.5.1

Usage

Create and add an instance of ColorSlider to your view hierarchy.

let colorSlider = ColorSlider()
colorSlider.frame = CGRectMake(0, 0, 12, 150)
view.addSubview(colorSlider)

ColorSlider is a subclass of UIControl and supports the following UIControlEvents:

  • .touchDown
  • .valueChanged
  • .touchUpInside
  • .touchUpOutside
  • .touchCancel

You can get the currently selected color with the color property.

colorSlider.addTarget(self, action: #selector(ViewController.changedColor(_:)), forControlEvents: .valueChanged)

func changedColor(_ slider: ColorSlider) {
    var color = slider.color
    // ...
}

Enable live color preview:

colorSlider.previewEnabled = true

Use a horizontal slider:

colorSlider.orientation = .horizontal

Customize appearance attributes:

colorSlider.borderWidth = 2.0
colorSlider.borderColor = UIColor.white

Please see the documentation and check out the sample app (Sketchpad) for more details.

Installation

CocoaPods

ColorSlider is available for installation using CocoaPods. To integrate, add the following to your Podfile`:

platform :ios, '9.0'
use_frameworks!

pod 'ColorSlider', '~> 3.0'

Carthage

ColorSlider is also available for installation using Carthage. To integrate, add the following to your Cartfile:

github "gizmosachin/ColorSlider" >= 3.0

Swift Package Manager

ColorSlider is also available for installation using the Swift Package Manager. Add the following to your Package.swift:

import PackageDescription

let package = Package(
    name: "MyProject",
    dependencies: [
        .Package(url: "https://github.com/gizmosachin/ColorSlider.git", majorVersion: 0),
    ]
)

Manual

You can also simply copy ColorSlider.swift into your Xcode project.

Example Project

ColorSlider comes with an example project called Sketchpad, a simple drawing app. To try it, install CocoaPods and run pod install under the Example directory. Then, open Sketchpad.xcworkspace.

How it Works

ColorSlider uses HSB and defaults to a saturation and brightness: 100%.

When the orientation is set to .vertical, dragging vertically adjusts the hue, and dragging outside adjusts the saturation and brightness as follows:

  • Inside the frame, dragging vertically adjusts the hue
  • Outside the frame, dragging horizontally adjusts the saturation
  • Outside the frame, dragging vertically adjusts the brightness

Adjusting the brightness lets you select black and white by first dragging on the slider, then moving your finger outside the frame to the top left (to select white) or bottom left (to select black) of the superview.

License

ColorSlider is available under the MIT license, see the LICENSE file for more information.

colorslider's People

Contributors

andrewsb avatar gizmosachin avatar kkapitan avatar ziewvater avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.