简体   繁体   English

增加NSSlider 0.1? macOS,斯威夫特

[英]Increment NSSlider by 0.1? macOS, Swift

I have a NSSlider where the minimum is 0.6 and maximum is 1. 我有一个NSSlider,其中最小值为0.6,最大值为1。

I want to be able to increment by 0.1 and not have values such as 0.6493 or 0.8435 我希望能够增加0.1,而不是像0.6493或0.8435这样的值

How would I accomplish this? 我怎么做到这一点?

I have the function 我有这个功能

@IBAction func slider(sender : NSSlider) {
    var x: Double = sender.doubleValue
    // do something
}

Thanks. 谢谢。

Try this format : 试试这种格式:

@IBAction func slider(sender : NSSlider) {

  let value = sender.value

  // "%.1f" show how many decimals you want to show
  let formatted = String(format: "%.1f", value)

  //formatted will be printed 0.X

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM