Skip to content

Instantly share code, notes, and snippets.

@hamada147
Last active June 18, 2020 22:23
Show Gist options
  • Save hamada147/855b4d995e2e1fe8246c5f914ffe31c5 to your computer and use it in GitHub Desktop.
Save hamada147/855b4d995e2e1fe8246c5f914ffe31c5 to your computer and use it in GitHub Desktop.
How to check in UISlider function which Button is selected
/**
* be sure that the slider's continuous property is also set.
* On the other hand, if you don't want the event to fire as the user is sliding and only when they finish sliding,
* set continuous to NO (or uncheck in IB)
*/
class ViewController: UIViewController {
@IBOutlet weak var slider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
/// add on value change listner
self.slider.addTarget(self, action: #selector(sliderDidChange(_:)), for: .valueChanged)
}
/// on value change function
@objc
func sliderDidChange(_ sender: UISlider) {
// check button value here then update the wanted UILabel
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment