gpt4 book ai didi

swift - "use of unresolved identifier"环球银行金融电信协会

转载 作者:行者123 更新时间:2023-11-30 10:07:46 25 4
gpt4 key购买 nike

错误

use of unresolved identifier 'slider'

到了它说的地方

var sliderValue=slider.value

有什么问题吗?

 import UIKit

class ViewController: UIViewController {

@IBAction func colorChanger(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 }

最佳答案

据我(或 Swift ;-))所知,您的代码中没有定义 slider 属性。

相反,您的方法中有一个名为 sender 的参数,它是一个 UISlider,因此请尝试使用它。

var sliderValue = sender.value

sender重命名为slider

这是一种实现方法(在 @leo-dabus 的帮助下)。我也冒昧地清理了你的代码,抱歉:-)

import UIKit

class ViewController: UIViewController {

@IBAction func colorChanger(sender: UISlider) {
// creates variable holding the value from slider
let sliderValue = CGFloat(sender.value)

// changes the newBackgroundColor variable to new color values.
let newBackgroundColor = UIColor(hue: sliderValue, saturation: 0.5, brightness: 0.5, alpha: 0.5)

// changes the background color
view.backgroundColor = newBackgroundColor
}

关于swift - "use of unresolved identifier"环球银行金融电信协会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099696/

25 4 0
文章推荐: javascript - 拖动时的 Angular dragdrop css 类
文章推荐: java - 奥利奥 - 闪烁通知 LED
文章推荐: javascript - 如何将数组的数组转换为对象?
文章推荐: javascript - 验证电子邮件时显示
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com