【发布时间】:2015-01-25 11:09:16
【问题描述】:
我正在学习使用 Swift for iOS 中的控件。我正在尝试构建一个简单的应用程序,该应用程序使用 Slider 使用 UIColor 类调整屏幕的背景颜色。
// function is called when slider is moved.
@IBAction func sliderValueChanged(sender: UISlider) {
// creates variable to hold new color
var newBackgroundColor : UIColor
// creates variable holding the value from slider
var sliderValue = slider.value
// changes the newBackgroundColor variable to new color values.
newBackgroundColor = UIColor(hue: sliderValue, saturation: 0.5, brightness: 0.5, alpha: 0.5)
// changes the background color
self.view.backgroundColor = newBackgroundColor
滑块似乎连接正确,调整背景的代码有效。我创建了一个变量来保存滑块的值(介于 0.0 和 1.0 之间),但是当我尝试将此变量插入 UIColor 代码时,它会出现错误“Extra Argument Saturation In Call”。
PS:对不起,如果代码是杂乱无章的。这是我的第一篇文章(我还不能发布图片)。
【问题讨论】: