adjusting label to slider value swift

后端 未结 6 1645
南旧
南旧 2021-01-01 14:44

I have a slider and label in my swift project. On the storyboard, I control dragged my slider onto my controller class for that page and created an outlet and also an action

6条回答
  •  遥遥无期
    2021-01-01 14:58

    This is what I did and it seemed to have worked:

    // For the slider
    @IBOutlet weak var slider: UISlider!
    
    // For the label displaying the slider value
    @IBOutlet weak var sliderVal: UILabel!
    
    // For the "submit" button action
    @IBAction func newSliderValue(_ sender: Any) {
        sliderVal.text = String(slider.value)
    }
    

    Note, I used a button to submit my new slider value, not what you did.

提交回复
热议问题