Krutarth Patel Krutarth Patel - 2 years ago 138
Swift Question

How to Change Opacity of Selected background color of View using UISlider?

I want to create custom colour picker according to my requirement.
I do not want to go with third party.
How can I increase or decrease the opacity of particular when slider value is changed?

screenshot is below:

Slider demo in xcode

Answer Source

After you set up your slider and create a connection to the value change like so....

enter image description here

Then change the minimum and maximum values of the slider to 0 to 1

then implement this inside your sliderValueChanged handler

@IBAction func sliderValueChanged(sender: UISlider) {
     var currentValue = Int(sender.value)

     self.view.backgroundColor = UIColor(white: 1, alpha: sender.value)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download