gpt4 book ai didi

ios - CGRect 调用中的 Swift 额外参数 "width"

转载 作者:行者123 更新时间:2023-11-28 11:21:16 30 4
gpt4 key购买 nike

我正在尝试在代码中添加一些按钮我得到一个错误“调用中的额外参数‘width’”

        let yPos = txt.frame.origin.y + txt.frame.height


for i in 0..<count {
let yt : Int = i*40 + yPos
//let b = UIButton(frame: CGRect(x: xPos, y: 40, width: 100, height: 30))
var b = UIButton(frame: CGRect(x: xPos, y: yt, width: 100, height: 30))
b.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "test:"))
b.backgroundColor = UIColor.blackColor()
b.tag = i
self.addSubview(b)
}

我不知道是什么问题。我试图将所有参数都转换为 Int 但我得到了同样的错误。有什么建议么?

最佳答案

我的错误是我不得不将所有参数都转换到 CGFloat

       for i in 0...2 {
let yt : CGFloat = CGFloat(i*40) + yPos
//let b = UIButton(frame: CGRect(x: xPos, y: 40, width: 100, height: 30))
var b = UIButton(frame: CGRect(x: xPos, y: yt, width: 100, height: 30))
b.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "test:"))
b.backgroundColor = UIColor.blackColor()
b.tag = i
self.addSubview(b)
}

关于ios - CGRect 调用中的 Swift 额外参数 "width",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27885469/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com