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
ColorSliderand its preview via a simple API, and receive callbacks viaUIControlEvents.Use the convenience initializer to create a
.verticalColorSlider with a live preview that appears to the.leftof it:let colorSlider = ColorSlider(orientation: .vertical, previewSide: .left)You can create a custom preview view using the
ColorSliderPreviewingprotocol, or by subclassingDefaultPreviewView. 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
UIControlsubclass and fully supports the followingUIControlEvents:.valueChanged.touchDown.touchUpInside.touchUpOutside.touchCancel
Once adding your class as a target, you can get callbacks via the
colorproperty: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 = falseColorSlider uses the HSB color standard internally. You can set the
See moresaturationof your ColorSlider’sgradientViewto change the saturation of colors on the slider. See theGradientViewandHSBColorfor more details on how colors are calculated.Declaration
Swift
public class ColorSlider: UIControl
-
A gradient view that acts as the background of any
ColorSlider. This class draws colors based on theorientationpassed to the initializer and determines the output color ofColorSliderafter a touch event.Customize the appearance of ColorSlider by setting layer properties on this class, including
See moreborderWidth,borderColor, andcornerRadius.Declaration
Swift
public final class GradientView: UIView
-
The default preview view of a
ColorSlider.Appears to the given
sideof the associatedColorSliderat the point of the currently selected color with an offset ofoffsetAmountand a scale given byscaleAmountsfor a given state.You can subclass this class and pass it as a preview to
See moreColorSliderto customize its appearance or animation. You may also create your own customUIViewand conform to thePreviewViewprotocol and pass that toColorSlider‘s initializer.Declaration
Swift
public class DefaultPreviewView: UIView
View on GitHub
Install in Dash
Classes Reference