gizmosachin / ColorSlider

🎨 Snapchat-style color picker in Swift
MIT License
288 stars 53 forks source link

Being able to set a value #19

Closed jbouaziz closed 7 years ago

jbouaziz commented 7 years ago

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?

gizmosachin commented 7 years ago

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

gizmosachin commented 7 years ago

This has been merged in v4.0.

jbouaziz commented 7 years ago

Thanks !

jlichti commented 7 years ago

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))
akhilcb commented 7 years ago

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.