How to use Slider UI control in IOS

Last Updated: October 19, 2017

In this article I am going to show you how to use the Slider UI control using Swift language
First you place the Label and Slider UI control on the ViewControl

Then you need two outlets for UILabel and UISlider

 
@IBOutlet weak var labelValue: UILabel!
@IBOutlet weak var slider: UISlider!

Next you need action for UISlider
When you move the slider valueChangedSlider action will be called and change the text of the UILabel

  
@IBAction func valueChangedSlider(_ sender: UISlider) {
       labelValue.text = sender.value.description
}

So this is your complete for the slider example

 
import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var labelValue: UILabel!
    @IBOutlet weak var slider: UISlider!
    @IBAction func valueChangedSlider(_ sender: UISlider) {
        labelValue.text = sender.value.description
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}