我是一个快速的新手,相信我,我已经搜索并寻找答案了。我想创建UISliders,从Swift中的一组数字中获取它们的值。它是一个相机应用程序,因此示例数组应该是显而易见的。
@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的快门速度! 从我看到的那里,这不是一个简单的,因为没有数学表示从数组中计算。它甚至可能吗?
答案 0 :(得分:1)
我不太确定我明白你想要的是什么,但我猜这是对的。
// 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)"
}
答案 1 :(得分:0)
这对我有用
@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。一定要看看聊天。