尝试使用滑块调整 Swift / iOS 中的颜色 8 - 出现 "Extra Argument Saturation In Call" 错误
Trying to use Slider to adjust color in Swift / iOS 8 - get "Extra Argument Saturation In Call" error
我正在学习将 Swift 中的控件用于 iOS。我正在尝试构建一个简单的应用程序,它使用 Slider 使用 UIColor class.
调整屏幕的背景颜色
// 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:抱歉,如果代码有问题。这是我的第一个 post(我还不能 post 图片)。
因为sliderValue
是Float
类型,而hue是CGFloat
类型。你可以这样投。
let sliderValue = CGFloat(slider.value)
我正在学习将 Swift 中的控件用于 iOS。我正在尝试构建一个简单的应用程序,它使用 Slider 使用 UIColor class.
调整屏幕的背景颜色// 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:抱歉,如果代码有问题。这是我的第一个 post(我还不能 post 图片)。
因为sliderValue
是Float
类型,而hue是CGFloat
类型。你可以这样投。
let sliderValue = CGFloat(slider.value)