xcode 我如何制作具有步长值的 UISlider
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35452185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:33:05 来源:igfitidea点击:
How can i make a UISlider with step value
提问by Flemming Ovesen
Hope someone can help me. Im trying to make a UISlider with step value from 1 to 5 in Swift
希望可以有人帮帮我。我试图在 Swift 中制作一个步长值从 1 到 5 的 UISlider
My code are:
我的代码是:
@IBAction func yearChange(sender: UISlider) {
let step: Float = 1
let currentValue = round(sender.value / step) * step
print("\(currentValue) year")
}
回答by Flemming Ovesen
i solved the issue with this code :
我用这段代码解决了这个问题:
let step: Float = 1
let roundedValue = round(sender.value / step) * step
sender.value = roundedValue
回答by Ethan
hope this help
希望这有帮助
let slider = UISlider()
let total: Float = 5
slider.maximumValue = total
slider.minimumValue = 1
@IBAction func yearChange(sender: UISlider) {
let step: Float = 1
let currentValue = round((sender.value - sender.minimumValue) / step)
print("\(currentValue) year")
}