var slider = UISlider()
var timer = NSTimer()
slider.frame = CGRectMake(10, 200, view.frame.size.width-20, 100)
slider.backgroundColor = UIColor.lightGrayColor()
slider.minimumValue = 0
slider.maximumValue = 100
slider.value = 0
slider.addTarget(self, action: #selector(ViewController.sliderClicked), forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(slider)
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewController.tiemsClicked), userInfo: nil, repeats: true)
func tiemsClicked() {
slider.value += 1
if (slider.value == 100) {
slider.value = 0
timer.invalidate()
}
}
func sliderClicked() {
print(self.slider.value)
if (slider.value == 100) {
slider.value = 0
}
}