swift中UISlider的

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.setupSlider()
    }
    
    func setupSlider() {
        let slider = UISlider(frame: CGRect(x: 10, y: 100, width: 300, height: 90))
        // 最小值
        slider.minimumValue = 10
        // 最大值
        slider.maximumValue = 100
        // 当前的默认值
//        slider.value = 50
        slider.setValue(50, animated: true)
        
        slider.isContinuous = false
//        slider.addTarget(self, action: #selector(sliderValueChange), for: .valueChanged)
        slider.addTarget(self, action: #selector(sliderValueChange(_:)), for: .valueChanged)
        
        self.view.addSubview(slider)
    }
    func sliderValueChange(_ slider: UISlider) {
        print("sliderValueChange")
    }
//    func sliderValueChange(){
//        print("bbb")
//        
//    }
}

你可能感兴趣的:(swift中UISlider的)