func testUiSlider() { let slider = UiSlider(frame: CGRectMake(0,70,300,40)) slider.center = self.view.center slider.minimumValue = 0 slider.maximumValue = 1 slider.value = 0.5 slider.continuous=false //滑块滑动停止后才触发ValueChanged事件 slider.addTarget(self,action: "valuechage:",forControlEvents: UIControlEvents.ValueChanged) self.view.addSubview(slider) } func valuechage(sender: UiSlider) { print(sender.value) }原文链接:https://www.f2er.com/swift/323844.html