Reputation: 3
I am trying to both reset the slider value, as well as have the slider value display in the label without having to tap and drag on the slider. At the moment, the value does not show unless the slider it tapped and dragged.
func setValue(_ value: Float, animated: Bool)
Apple has suggested the code above to change the value, but I am unsure how to use it. It also says there is no ".value" property for sliders, which is what a lot of sources online are saying to use.
The code is have so far for the slider is below.
@IBAction func theSlider(_ sender: UISlider) {
myBet.text = String(Int(sender.value * Float(myScore)))
betValue = Float(myBet.text!)!
}
Upvotes: 0
Views: 1096
Reputation: 876
If your slider is of type UISlider
, then it will have the instance method you mention.
And you can use it like this:
@IBAction func theSlider(_ sender: UISlider) {
myBet.text = String(Int(sender.value * Float(myScore)))
betValue = Float(myBet.text!)!
sender.setValue(betValue, animated: false)
}
if you want the animation effect, you could pass true to animated.
Upvotes: 1