Classes

The following classes are available globally.

  • ColorSlider is a customizable color picker with live preview.

    Inspired by Snapchat, ColorSlider lets you drag to select black, white, or any color in between. Customize ColorSlider and its preview via a simple API, and receive callbacks via UIControlEvents.

    Use the convenience initializer to create a .vertical ColorSlider with a live preview that appears to the .left of it:

    let colorSlider = ColorSlider(orientation: .vertical, previewSide: .left)
    

    You can create a custom preview view using the ColorSliderPreviewing protocol, or by subclassing DefaultPreviewView. To pass in a custom preview view, simply use the default initializer instead:

    let myPreviewView = MyPreviewView()
    let colorSlider = ColorSlider(orientation: .vertical, previewView: myPreviewView)
    

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

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

    Once adding your class as a target, you can get callbacks via the color property:

    colorSlider.addTarget(self, action: #selector(ViewController.changedColor(_:)), forControlEvents: .valueChanged)
    
    func changedColor(_ slider: ColorSlider) {
        var color = slider.color
        // ...
    }
    

    Customize the appearance of ColorSlider by setting properties on the gradientView:

    // Add a border
    colorSlider.gradientView.layer.borderWidth = 2.0
    colorSlider.gradientView.layer.borderColor = UIColor.white
    
    // Disable rounded corners
    colorSlider.gradientView.automaticallyAdjustsCornerRadius = false
    

    ColorSlider uses the HSB color standard internally. You can set the saturation of your ColorSlider’s gradientView to change the saturation of colors on the slider. See the GradientView and HSBColor for more details on how colors are calculated.

    See more

    Declaration

    Swift

    public class ColorSlider: UIControl
  • A gradient view that acts as the background of any ColorSlider. This class draws colors based on the orientation passed to the initializer and determines the output color of ColorSlider after a touch event.

    Customize the appearance of ColorSlider by setting layer properties on this class, including borderWidth, borderColor, and cornerRadius.

    See more

    Declaration

    Swift

    public final class GradientView: UIView
  • The default preview view of a ColorSlider.

    Appears to the given side of the associated ColorSlider at the point of the currently selected color with an offset of offsetAmount and a scale given by scaleAmounts for a given state.

    You can subclass this class and pass it as a preview to ColorSlider to customize its appearance or animation. You may also create your own custom UIView and conform to the PreviewView protocol and pass that to ColorSlider‘s initializer.

    See more

    Declaration

    Swift

    public class DefaultPreviewView: UIView