【问题标题】:Swift Extra argument "width" in call in CGRectCGRect中调用中的Swift Extra参数“width”
【发布时间】:2015-01-11 09:00:19
【问题描述】:

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

        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 但我得到了同样的错误。 有什么建议么?

【问题讨论】:

    标签: ios swift uibutton


    【解决方案1】:

    我的错误是我必须将所有参数都转换为 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)
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多