gizmosachin / ColorSlider

🎨 Snapchat-style color picker in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Being able to set a value

jbouaziz opened this issue · comments

It would be great to be able to force a color value at any time on the Color slider. We could imagine that we'd want to save the latest selected color in the user settings and set that color back when he comes back.

What do you think?

Great idea! I have a pull request I'm working on here and I'll try to add something like that in. Thanks!

This has been merged in v4.0.

Thanks !

I'm trying to set a default value for the slider and had to make a couple changes. I'm using autolayout so setting color right away was not positioning the preview view correctly.

I moved these lines to the default center area of layoutSubviews() and now the view shows up in the right spot.

// Set default preview center
case .horizontal where preview.center.y != bounds.midY,
 .vertical where preview.center.x != bounds.midX:
let sliderProgress = gradientView.calculateSliderProgress(for: internalColor)
                
// centerPreview only uses the x or y value based on the orientation and ignores the other value.
centerPreview(at: CGPoint(x: sliderProgress * bounds.width, y: sliderProgress * bounds.height))

This seems to be an issue for me too. Can we please have the above code merged to master branch so that cocoapod will have same fix? Right now when we set a color, it is not updating the preview view position.