Full preview view customization via the ColorPreviewable protocol.
Customizable DefaultPreviewView that supports custom animation duration, scale, size, and offset.
Black and white colors are now accessible from within the slider (#15).
New demo project that no longer requires external dependencies or Cocoapods.
Swift 4.
I wanted to minimize code changes needed, but refactoring into multiple files and new preview behavior required several changes to properties / property names. To mitigate the effects of this:
@available(*, obsoleted: 4.0... statements that throw compiler errors when an app is updated to ColorSlider 4 and suggest the replacement or equivalent for obsoleted properties.
I wrote the following breaking changes doc, which I'll put in the release notes for ColorSlider 4 once it's merged:
Breaking Changes
Live Preview
The color preview is now enabled by default. previewEnabled has been replaced by a previewView parameter in the initializer. Pass nil for this property to disable the preview.
Preview behavior has changed. A minimized version of the preview now shows on top of ColorSlider, even when touches are not being tracked, indicating the color currently selected (given by color).
previewDimension has been replaced and the default preview view now resizes based on the size of the slider. To manually set the preview size:
previewOffset is now a property on the DefaultPreviewView and designates the offset from the center of the ColorSlider rather than the edge (as it did before):
if let previewView = colorSlider.previewView as? DefaultPreviewView {
previewView.offsetAmount = 60
}
To hide the minimized preview and mimic the behavior of the old preview view:
if let previewView = colorSlider.previewView as? DefaultPreviewView {
previewView.scaleAmounts[.inactive] = 0.001
}
There are several other properties on the DefaultPreviewView that can be customized. Alternatively, you can now subclass DefaultPreviewView or implement ColorPreviewable in a UIView subclass and pass it into the ColorSlider initializer to use a completely custom preview.
Appearance
borderWidth has been replaced by gradientView.layer.borderWidth.
borderColor has been replaced by gradientView.layer.borderColor and now requires a CGColor instead of a UIColor.
cornerRadius has been replaced by gradientView.layer.cornerRadius instead.
setsCornerRadiusAutomatically has been replaced by gradientView.automaticallyAdjustsCornerRadius
orientation is no longer settable after initialization. Pass the orientation in the initializer instead.
ColorPreviewable
protocol.DefaultPreviewView
that supports custom animation duration, scale, size, and offset.I wanted to minimize code changes needed, but refactoring into multiple files and new preview behavior required several changes to properties / property names. To mitigate the effects of this:
@available(*, obsoleted: 4.0...
statements that throw compiler errors when an app is updated to ColorSlider 4 and suggest the replacement or equivalent for obsoleted properties.Breaking Changes
Live Preview
The color preview is now enabled by default.
previewEnabled
has been replaced by apreviewView
parameter in the initializer. Passnil
for this property to disable the preview.Preview behavior has changed. A minimized version of the preview now shows on top of ColorSlider, even when touches are not being tracked, indicating the color currently selected (given by
color
).previewDimension
has been replaced and the default preview view now resizes based on the size of the slider. To manually set the preview size:previewOffset
is now a property on theDefaultPreviewView
and designates the offset from the center of theColorSlider
rather than the edge (as it did before):To hide the minimized preview and mimic the behavior of the old preview view:
There are several other properties on the
DefaultPreviewView
that can be customized. Alternatively, you can now subclassDefaultPreviewView
or implementColorPreviewable
in aUIView
subclass and pass it into theColorSlider
initializer to use a completely custom preview.Appearance
borderWidth
has been replaced bygradientView.layer.borderWidth
.borderColor
has been replaced bygradientView.layer.borderColor
and now requires aCGColor
instead of aUIColor
.cornerRadius
has been replaced bygradientView.layer.cornerRadius
instead.setsCornerRadiusAutomatically
has been replaced bygradientView.automaticallyAdjustsCornerRadius
orientation
is no longer settable after initialization. Pass the orientation in the initializer instead.