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 viaUIControlEvents
.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 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
UIControl
subclass and fully supports the followingUIControlEvents
:.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
See moresaturation
of your ColorSlider’sgradientView
to change the saturation of colors on the slider. See theGradientView
andHSBColor
for 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 theorientation
passed to the initializer and determines the output color ofColorSlider
after 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
side
of the associatedColorSlider
at the point of the currently selected color with an offset ofoffsetAmount
and a scale given byscaleAmounts
for a given state.You can subclass this class and pass it as a preview to
See moreColorSlider
to customize its appearance or animation. You may also create your own customUIView
and conform to thePreviewView
protocol and pass that toColorSlider
‘s initializer.Declaration
Swift
public class DefaultPreviewView: UIView