Swift 从数字数组中获取值的 UISlider

Swift UISlider that gets its values from an array of numbers

我是 swift 的新手,相信我,我已经搜索并搜索了答案。我想创建从 Swift 中的数字数组获取值的 UISlider。它是一个相机应用程序,因此示例数组应该很明显。

@IBAction func isoValueChanged(sender: UISlider) {
    let isoArray = ["24", "32", "50","64","80","100","125","160","200","250","320","400","500","640","720","800","1000","1250","1600","1800"] // available iPhone 6s ISO settings I believe
    let currentValue = // What do I need?
    isoText.text = "\(currentValue)"
}

更难的是代表 1/1000 - 32 的快门速度! 据我所知,这不是一件容易的事,因为没有数学表示法可以从数组中计算出来。有可能吗?

我不太确定我明白你想要这个的目的,但我猜这是对的。

// Global Variable or something like this (accessible from multiple functions)
let isoArray = ["24", "32", "50","64","80","100","125","160","200","250","320","400","500","640","720","800","1000","1250","1600","1800"] // available iPhone 6s ISO settings I believe

func functionThatCreatesTheSliderYo(...) {
    slider.minimumValue = 0
    slider.maximumValue = isoArray.count
    slider.continuous = false
}

@IBAction func isoValueChanged(sender: UISlider) {
    // instead of Int(val) you may want to round(val) for a better UI
    let currentValue = isoArray[Int(sender.value)]
    isoText.text = "\(currentValue)"
}

这对我有用

    @IBAction func isoValueChanged(sender: UISlider) {
    let isoArray = ["24", "32", "50","64","80","100","125","160","200","250","320","400","500","640","720","800","1000","1250","1600","1800"]
    let currentValue = isoArray[Int(sender.value)]
    isoText.text = "\(currentValue)"

}

在 Swift 中应该如此简单。非常感谢 Ty。不过一定要看看聊天。