adjusting label to slider value swift

后端 未结 6 690
清歌不尽
清歌不尽 2021-01-01 14:34

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 15:00

    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.

提交回复
热议问题